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

Allow arbitrary field names in ValidationError #273

Closed
evgeny-sureev opened this Issue Sep 11, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@evgeny-sureev
Contributor

evgeny-sureev commented Sep 11, 2015

I tried to modify example from docs to use missing field name instead of default "_schema", but got an KeyError.

class MySchema(Schema):
    foo = fields.Int()
    bar = fields.Int()

    @validates_schema(pass_original=True)
    def check_unknown_fields(self, data, original_data):
        for key in original_data:
            if key not in self.fields:
                raise ValidationError('Unknown field name', key)

schema = MySchema()
result, errors = schema.load({'foo': 1, 'bar': 2, 'baz': 3})  # throws KeyError in _run_validator
errors  # this is what I am trying to achieve: {'baz': ['Unknown field name']}
@sloria

This comment has been minimized.

Member

sloria commented Sep 13, 2015

Yes, I think it would be good to allow any key name to be passed and stored. Pull requests welcome!

evgeny-sureev added a commit to evgeny-sureev/marshmallow that referenced this issue Sep 14, 2015

@evgeny-sureev

This comment has been minimized.

Contributor

evgeny-sureev commented Sep 14, 2015

Ok, I made PR #275

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

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

Merge pull request #275 from evgeny-sureev/arbitrary-error-field-names
Allow arbitrary field names in ValidationError #273
@sloria

This comment has been minimized.

Member

sloria commented Sep 16, 2015

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment