Repository navigation
fix: default relationship fields to required=False to avoid missing data errors on load (#664) - #745
Open
Fire162 wants to merge 1 commit into
Conversation
…g on null keys (marshmallow-code#664) - Set default required=False on relationship fields generated by ModelConverter while keeping allow_none matching relationship nullability. - Prevent ValidationError ('Missing data for required field') when deserializing models with include_relationships=True using foreign key values or nested data. - Avoid SAWarning in Related._get_existing_instance when all lookup values are None. - Add regression tests for schema.load with non-nullable relationships and warning prevention.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #664.
In #645, relationship fields generated from non-nullable foreign keys were marked with
required: not nullable(i.e.required=True). Whileallow_none=Falsecorrectly prevents assigningNoneto non-nullable relationships, marking relationship fields asrequired=Trueby default breaks deserialization when:include_relationships=Trueandinclude_fk=Trueare both active, requiring callers to redundantly provide both the foreign key ID and the related object.Changes
ModelConverter._add_relationship_kwargstorequired=Falsewhile preservingallow_none=nullable(so settingNoneon non-nullable relationships remains rejected).Related._get_existing_instancewhen all primary keylookup_valuesareNone, raisingNoResultFoundwithout triggering SQLAlchemy'sSAWarning: fully NULL primary key identity cannot load any object.test_conversion.pyand adds regression tests intest_sqlalchemy_schema.pyverifying deserialization with non-nullable relationships and warning prevention.