Skip to content

Fix nested partial to use attr_name instead of data_key for prefix#2903

Open
bysiber wants to merge 2 commits intomarshmallow-code:devfrom
bysiber:fix/nested-partial-data-key
Open

Fix nested partial to use attr_name instead of data_key for prefix#2903
bysiber wants to merge 2 commits intomarshmallow-code:devfrom
bysiber:fix/nested-partial-data-key

Conversation

@bysiber
Copy link

@bysiber bysiber commented Feb 20, 2026

Summary

When using dot-delimited partial with nested schemas, the sub-partial prefix is derived from field_name (the data_key) instead of attr_name. This causes the nested partial to silently break when a field has data_key set.

Problem

The partial parameter accepts dot-delimited attribute names:

schema.load(data, partial=("address.zip_code",))

In _deserialize, the top-level partial check correctly uses attr_name:

partial_is_collection and attr_name in partial

But the nested sub-partial extraction uses field_name (which is the data_key if set):

prefix = field_name + "."  # field_name could be "homeAddress" (data_key)

If a field is declared as address = Nested(AddressSchema, data_key="homeAddress"), then:

  • attr_name = "address"
  • field_name = "homeAddress" (from data_key)
  • User passes partial=("address.zip_code",)
  • prefix = "homeAddress." — doesn't match "address.zip_code"
  • Result: sub_partial is empty, nested schema doesn't get partial

Fix

Use attr_name instead of field_name for the prefix, consistent with how the top-level partial check works.

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.
@bysiber bysiber force-pushed the fix/nested-partial-data-key branch from 940b32c to 1be084f Compare February 20, 2026 06:56
Copy link
Member

@sloria sloria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a test to demonstrate the issue/fix?

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.

3 participants