-
-
Notifications
You must be signed in to change notification settings - Fork 629
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
Bug: several nested partial issues (sequence partial, data key, schema initialized partial) #2041
Comments
Hi. Thanks for the report and PR.
This line result = SchemaB().load(test_data, partial={"original"}) says that original may be omitted. However, you're not omitting it, you're providing an incomplete "original". test_data = {"original": {"second_nested": 42}} What you want to do is result = SchemaB().load(test_data, partial={"original.first_nested"})
|
Thank you for respond! Regarding first point... Do the library have any other way to mark nested field as fully partial then? By "fully partial" I mean the field by itself with all children of this field recursively. Might it be "original.*" or something? In current PR I can remove code which touching logic for first point to merge fixes for 2nd and 3rd issues. Then as soon as we'll know what to do with the first one I can open another PR. What do you think? |
One more thing regarding first point... If it's expected that only selected field marked as partial does it mean that passing |
I just ran into issues 2 and 3 from the bug report above. Currently working around it with a custom decorator based on #438 (comment). def _partial_schema(schema_cls, **kwargs):
"""
Create a modified instance of a schema class that has all of it's fields
configured to support partial loading and dumping.
https://github.com/marshmallow-code/marshmallow/issues/438#issuecomment-673428463
"""
if 'partial' not in kwargs:
kwargs['partial'] = True
schema = schema_cls(**kwargs)
for field in schema.fields.values():
# do not require field value
field.required = False
# do not provide default value when loading or dumping
field.load_default = missing
field.dump_default = missing
return schema |
For what it's worth, I agree that point 1 is by design, but it might be nice to have a separate |
Apologies if this hypothesis has been confirmed already but, if indeed it does not have any effect to do |
Possibly. People could also be using a partial instance created earlier and used in a place where partial is needed. But I admit this is a bit convoluted. Anyway, fixing this could arguably be considered a bugfix. |
+1 for a passed-through |
Hello there! I was playing with
partial
attribute forNested
fields and faced several issues related to them.When you providing sequence as
partial
instead of bool nested schema continue to be required:It'll raise
ValidationError: {'original': {'first_nested': ['Missing data for required field.']}}
but expected validation without errors.When you providing
partial
argument while initializingNested
field it'll have no effect:It'll raise the same
ValidationError: {'original': {'first_nested': ['Missing data for required field.']}}
error instead of passing validation.While digging into the reason of mentioned issues I found the code which potentially causing another error. Testing showed that I'm right. So:
When schema fields have specified
data_key
providing sequence aspartial
must contain data keys instead of original schema defined field names:It'll raise
ValidationError: {'orig': {'frst_nst': ['Missing data for required field.']}}
. To make it work you forced to use"orig.first_nested"
instead. I believe that this approach isn't correct and we need to use field name, not data key.All of the mentioned issues fixed in the PR that you can see in the attachments below.
The text was updated successfully, but these errors were encountered: