Opened 11 years ago

Closed 11 years ago

#21555 closed Bug (fixed)

ValidationError is not picklable

Reported by: Alex Hayes Owned by: nobody
Component: Forms Version: dev
Severity: Normal Keywords:
Cc: loic@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have a use case where I'd like to pickle ValidationError however it throws up as error:

For example, I'd expect the following to work:

import pickle
from django.core.exceptions import ValidationError
pickle.loads(pickle.dumps(ValidationError('eggs', 'sausage')))

Results in:

TypeError: __init__() takes at least 2 arguments (1 given)

The reason for this is because ValidationError does not call super.

Attachments (1)

ticket-21555-rev1.patch (1.1 KB ) - added by Alex Hayes 11 years ago.

Download all attachments as: .zip

Change History (4)

by Alex Hayes, 11 years ago

Attachment: ticket-21555-rev1.patch added

comment:1 by loic84, 11 years ago

Cc: loic@… added
Triage Stage: UnreviewedAccepted

It's a good idea as PY2 can't pickle naive exceptions see: http://bugs.python.org/issue1692335 (fix was backported all the way to python 3.2).

Since we'd now be calling the constructor, I think it's good practice to pass all arguments so the args attribute holds meaningful information.

I've completed the test suite to ensure the more complex scenarios like nested ValidationError, or Validation with error_dict behave as expected.

PR https://github.com/django/django/pull/2022.

comment:2 by Tim Graham, 11 years ago

Component: UncategorizedForms
Triage Stage: AcceptedReady for checkin

comment:3 by Loic Bistuer <loic.bistuer@…>, 11 years ago

Resolution: fixed
Status: newclosed

In a8f4553aaecc7bc6775e0fd54f8c615c792b3d97:

Fixed #21555 -- Made ValidationError pickable.

Thanks trac username zanuxzan for the report and original patch.

Note: See TracTickets for help on using tickets.
Back to Top