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)
Change History (4)
by , 11 years ago
Attachment: | ticket-21555-rev1.patch added |
---|
comment:1 by , 11 years ago
Cc: | added |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 11 years ago
Component: | Uncategorized → Forms |
---|---|
Triage Stage: | Accepted → Ready for checkin |
comment:3 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
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
, orValidation
witherror_dict
behave as expected.PR https://github.com/django/django/pull/2022.