Skip to content
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

Improve documentation for make_object data validation #243

Closed
kissgyorgy opened this issue Jul 16, 2015 · 5 comments

Comments

Projects
None yet
2 participants
@kissgyorgy
Copy link

commented Jul 16, 2015

I took me a long time to realize if I want to use strictly valid data in make_object, I need to use strict=True option.

Something like this:

class LoginRequestSchema(Schema):
    login_name = fields.Str(required=True)
    password = fields.Str(required=True)

    def make_object(self, data):
        return UserLogin(data['login_name'], data['password'])

    class Meta:
        strict = True

because if I don't use strict, I got KeyError instead of the desired errors dict filled with messages on .load() call.
This should be emphasized in the documentation.
Or do I need to check for data validity in make_object? Also should I use something else instead make_object?

@sloria

This comment has been minimized.

Copy link
Member

commented Aug 2, 2015

Yes, I agree that the current behavior isn't intuitive. Ideally, make_object would not need to check for data validity--that should happen in the validators.

Some possible solutions:

  1. Don't call make_object unless the data are valid.
  2. Pass the errors dict to make_object.

Feedback welcome.

@sloria sloria added this to the 2.0.0 (final) milestone Aug 2, 2015

@kissgyorgy

This comment has been minimized.

Copy link
Author

commented Aug 3, 2015

How do I not call make_object if it is defined? AFAIK it is automatically called on Schema().dump(). Does it have a second parameter errors? It's even more confusing for me then.

@sloria

This comment has been minimized.

Copy link
Member

commented Aug 3, 2015

Sorry for the confusion--the above were proposals for a solution; they are not yet implemented.

@sloria sloria closed this in 8491d42 Aug 23, 2015

@sloria

This comment has been minimized.

Copy link
Member

commented Aug 23, 2015

I've decided to go with #1 (only call make_object if data are valid) in order to minimize breaking API changes. This is now documented in the API reference.

Closing this for now.

@kissgyorgy

This comment has been minimized.

Copy link
Author

commented Aug 24, 2015

This is great, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.