Opened 4 years ago

Closed 4 years ago

#21555 closed Bug (fixed)

ValidationError is not picklable

Reported by: Alex Hayes Owned by: nobody
Component: Forms Version: master
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


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 4 years ago.

Download all attachments as: .zip

Change History (4)

Changed 4 years ago by Alex Hayes

Attachment: ticket-21555-rev1.patch added

comment:1 Changed 4 years ago by loic84

Cc: loic@… added
Triage Stage: UnreviewedAccepted

It's a good idea as PY2 can't pickle naive exceptions see: (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.


comment:2 Changed 4 years ago by Tim Graham

Component: UncategorizedForms
Triage Stage: AcceptedReady for checkin

comment:3 Changed 4 years ago by Loic Bistuer <loic.bistuer@…>

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