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

Problems with make_object; plan for deprecation/removal #277

sloria opened this Issue Sep 16, 2015 · 1 comment


None yet
1 participant

sloria commented Sep 16, 2015

make_object causes problems when applying pre_load decorators that change the shape of the data (e.g. adding an "envelope").

Code to reproduce

from marshmallow import Schema, fields, post_load

class MySchema(Schema):
    foo = fields.Field()

    def post_load(self, data, many):
        envelope = 'data' if many else 'datum'
        ret = {envelope: data}
        return ret

schema = MySchema(many=True)
result = schema.load([{'foo': 42}, {'foo': 24}])



{'data': [{'foo': 42}, {'foo': 24}]}



The problem is in these lines:

if many:
result = [self.make_object(each) for each in result]
. They assume that result is a list, but it might not be if a pre_load or post_load handler changed the data.

Some less severe consequences of make_object are that it (1) may lead to unnecessary iteration over deserialized results and (2) is redundant with post_load.

@sloria sloria modified the milestone: 2.0.0rc2 Sep 16, 2015


This comment has been minimized.


sloria commented Sep 16, 2015

Here's the plan:

  • Mark make_object as deprecated in 2.0.0rc2
  • Document migration path in "Upgrading" docs
  • Remove make_object in 2.0.0 final

sloria added a commit that referenced this issue Sep 16, 2015

Deprecate make_object; update docs and upgrading guide
ref #277

Note: There is no DeprecationWarning raised when using make_object;
deprecation is only "enforced" by documentation.

make_object will be removed in the 2.0 final release.

This also updates some inaccuracies in the docs.

@sloria sloria modified the milestones: 2.0.0 (final), 2.0.0rc2 Sep 16, 2015

@sloria sloria closed this Sep 17, 2015

@srv-twry srv-twry referenced this issue Apr 21, 2018


Wrong schema validation #4655

1 of 3 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment