Our PATCH endpoints load with partial=(...) so a client may leave out fields it does not want to change. Dotted names reach into nested schemas: partial=("address.zip_code",) means the zip code of the address may be miss…
Our PATCH endpoints load with partial=(...) so a client may leave out fields it does not want to change. Dotted names reach into nested schemas: partial=("address.zip_code",) means the zip code of the address may be missing. This stops working as soon as the nested field has a data_key.
from marshmallow import Schema, fields
class AddressSchema(Schema):
zip_code = fields.String(required=True)
city = fields.String(required=True)
class PersonSchema(Schema):
address = fields.Nested(AddressSchema, data_key="homeAddress", required=True)
PersonSchema().load({"homeAddress": {"city": "Springfield"}}, partial=("address.zip_code",))
{"address": {"city": "Springfield"}}
ValidationError: {'homeAddress': {'zip_code': ['Missing data for required field.']}}
partial are field names (the attribute names on the schema) at every level, as they already are at the top level.partial=("homeAddress.zip_code",) must not skip anything; today it does.data_key, partial=True, and lists of nested schemas with a data_key on the list follow the same rule.Adapted from marshmallow-code/marshmallow (MIT).
Visible test command
pytest testsThe repository’s own tests. Run all tests includes them, and so does every submission.
Repository
nested-partial-ignores-attribute-name
Changes under src/ are evaluated.