-
-
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
Modified data silently truncated when using pass_original=True with multiple post_load methods #1755
Comments
I was unable to reproduce this with from marshmallow import Schema, fields, pre_load, post_load
class Test(Schema):
foo = fields.Str()
@post_load(pass_many=True)
def setup(self, data, **kwargs):
data.append({'foo': 'test'})
print(data)
return data
@post_load(pass_many=False, pass_original=True)
def test(self, data, original_data, **kwargs):
print(data, original_data)
return data
print(Test().load([{'foo': 'bar'}], many=True))
# [{'foo': 'bar'}, {'foo': 'test'}]
# {'foo': 'bar'} {'foo': 'bar'}
# [{'foo': 'bar'}] |
@deckar01 You are correct, I can't recreate this with pre_load anymore. |
sloria
changed the title
Modified data silently truncated when using pass_original=True in
Modified data silently truncated when using pass_original=True with multiple post_load methods
Jan 20, 2025
fixed in #2797 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
this happens when a
pre_load(pass_many=True)
hook appends items to the the input data collection, due to the usage of zip in _invoke_processors called bypost_load(pass_many=False)
:marshmallow/src/marshmallow/schema.py
Lines 1214 to 1218 in 3247666
It is arguable if modifying the input data in this way should be allowed, but it is not forbidden in the docs. I think using
itertools.zip_longest
would be a good choice here. Raising an exception iflen(data) != len(original_data)
is another option.Newly added items will not be validated too:
marshmallow/src/marshmallow/schema.py
Lines 1172 to 1174 in 3247666
I think
itertools.zip_longest
should be used here.Cheers. Alex
The text was updated successfully, but these errors were encountered: