RFC: Remove `fields` attribute from ValidationError
See original GitHub issueCurrently, 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
.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:12 (8 by maintainers)
Top Results From Across the Web
Form fields — Django 4.1.4 documentation
ValidationError : ['This field is required.'] >>> f.clean(None) Traceback (most ... Set the Form.use_required_attribute attribute to False to disable it.
Read more >removing field name from validation error message [duplicate]
in rails 3 i don't want to show field names in error messages. Anyone know how to do that ? validates_presence_of :title, :message...
Read more >marshmallow - Read the Docs
marshmallow is an ORM/ODM/framework-agnostic library for converting complex datatypes, such as objects, to and from native Python datatypes.
Read more >Model instance reference - Django documentation
This method will validate all fields on your model. The optional exclude argument lets you provide a set of field names to exclude...
Read more >Validation - Laravel - The PHP Framework For Web Artisans
The field under validation will be excluded from the request data returned by the validate and validated methods if the anotherfield field is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Good catch, @lafrech . I’ll get your webargs patch merged and released.
Once that’s in, I think @decaz 's use case can be met with something like
Edit: clean up
@decaz It’s released now.