Fix nested partial to use attr_name instead of data_key for prefix#2903
Open
bysiber wants to merge 2 commits intomarshmallow-code:devfrom
Open
Fix nested partial to use attr_name instead of data_key for prefix#2903bysiber wants to merge 2 commits intomarshmallow-code:devfrom
bysiber wants to merge 2 commits intomarshmallow-code:devfrom
Conversation
When building dot-delimited sub_partial for nested schemas, the prefix
was computed from field_name (which is data_key when set) instead of
attr_name. Since users specify partial fields using attribute names like
partial=("nested_field.child",), the prefix needs to match attr_name.
When data_key differs from attr_name, the prefix mismatch caused the
nested partial list to always be empty, so the nested schema never
received the partial option and required fields raised unexpected
validation errors.
940b32c to
1be084f
Compare
sloria
reviewed
Feb 20, 2026
Member
sloria
left a comment
There was a problem hiding this comment.
Can you please add a test to demonstrate the issue/fix?
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
When using dot-delimited
partialwith nested schemas, the sub-partial prefix is derived fromfield_name(thedata_key) instead ofattr_name. This causes the nested partial to silently break when a field hasdata_keyset.Problem
The
partialparameter accepts dot-delimited attribute names:In
_deserialize, the top-level partial check correctly usesattr_name:But the nested sub-partial extraction uses
field_name(which is thedata_keyif set):If a field is declared as
address = Nested(AddressSchema, data_key="homeAddress"), then:attr_name="address"field_name="homeAddress"(from data_key)partial=("address.zip_code",)prefix="homeAddress."— doesn't match"address.zip_code"sub_partialis empty, nested schema doesn't getpartialFix
Use
attr_nameinstead offield_namefor the prefix, consistent with how the top-level partial check works.