Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propose change for subclass inherited_fields override when include_fk=False #657

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

carterjc
Copy link

@carterjc carterjc commented Jan 30, 2025

Hi again, hope all is well.

This is sorta an addendum to #440.

I was running into an issue when upgrading my marshmallow-sqlalchemy version to 1.3 on a project because of the PR on the above report.

The existing tests seem to work because get_declared_fields in marshmallow/schema.py concatenates inherited_fields with class_fields. However, when trying to extend an AutoSchema with a marshmallow.schema.Schema to override a FK field, the new _maybe_filter_foreign_keys filters these fields out as well. I provided a test case in the PR to explain what I mean.

The way I thought to overcome this problem is by differentiating between the types of inheritance by some discriminator. I tried when fields are inherited from a Schema that is not a SQLAlchemySchema, the motivation being that SQLAlchemyAutoSchema introduces the include_fk field and the inheritance/overriding of this field is the nexus of the entire issue. I'm not sure if this is the best solution, but does work for the case that brought this issue to my attention and the existing test suite.

I'm open to any thoughts or suggestions. Thanks for all of your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant