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

Remove MarshallingError and UnmarshallingError in favor of a single ValidationError #160

Closed
sloria opened this Issue Mar 3, 2015 · 0 comments

Comments

Projects
None yet
1 participant
@sloria
Member

sloria commented Mar 3, 2015

Currently, MarshallingError and UnmarshallingError signal that an error should be stored in the errors dictionary during marshalling and unmarshalling.

These exceptions only served a purpose prior to commit 00a1866, when all exceptions were caught and reraised as (Un)MarshallingErrors. Now, they are only raised when a validation error occurs.

I propose to remove these exception classes in favor of a single ValidationError. Doing so would reduce the API and make accessing error messages when using strict mode much cleaner.

Current:

from marshmallow.exceptions import MarshallingError, UnmarshallingError, ValidationError

schema = MySchema(strict=True)

try:
    schema.dump(some_obj)
except MarshallingError as err:
    if isinstance(err.underlying_error, ValidationError):
        messages = err.underlying_error.messages
    # ...

try:
    schema.load(some_obj)
except UnmarshallingError as err:
    if isinstance(err.underlying_error, ValidationError):
        messages = err.underlying_error.messages
    # ...

Proposed:

from marshmallow.exceptions import ValidationError

schema = MySchema(strict=True)

try:
    schema.dump(some_obj)
except ValidationError as err:
    messages = err.messages
    # ...

try:
    schema.load(some_obj)
except ValidationError as err:
    messages = err.messages
    # ...

This could be implemented in conjunction with #128 .

WARNING: This would be a major breaking change for people using strict mode.

@sloria sloria added this to the 2.0-a milestone Mar 3, 2015

@sloria sloria added the refactor label Mar 5, 2015

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

Merge pull request #168 from marshmallow-code/validation-error
Improved strict mode; ValidationError; Deprecate UnmarshallingError and MarshallingError (issue #160)

@sloria sloria closed this Mar 16, 2015

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