Skip to content

RFC: Remove fields attribute from ValidationError #840

@sloria

Description

@sloria

Currently, ValidationError stores the field name and field instances associated with the error.

from marshmallow import Schema, fields

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

schema = MySchema()
try:
    schema.load({'foo': 'invalid'})
except Exception as error:
    print(error.fields)  # [<fields.Integer(...)>]

I propose removing the fields because it unnecessarily complicates the validation logic.

fields and field_names were added at a time (version 1.1.0 😓 ) when it was impossible to access all the error messages for a schema (see #63). It wasn't until 2.0 that it became possible to get the full error messages dict when using strict mode.

At this point, I don't see a use case for accessing ValidationError.fields.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions