Allow pickling dynamically created Model exception classes (DoesNotExist, MultipleObjectsReturned, RelatedObjectDoesNotExist)
Example:
>>> import django
>>> import pickle
>>> pickle.dumps(django.contrib.auth.models.User.DoesNotExist)
>>> PicklingError: Can't pickle <class 'django.contrib.auth.models.DoesNotExist'>: it's not found as django.contrib.auth.models.DoesNotExist
*Instances* of Model.DoesNotExist
are pickleable as fixed in #17776, however, the class itself is not. This is particularly problematic when using the Django test runner with the --parallel
option enabled when a Model.DoesNotExist
exception is raised. The result of this is the test runner bailing with a pickle.PicklingError
, making it exceptionally difficult to debug the cause of the Model.DoesNotExist
.
Change History
(12)
Type: |
Uncategorized → Bug
|
Description: |
modified (diff)
|
Description: |
modified (diff)
|
Triage Stage: |
Unreviewed → Accepted
|
Patch needs improvement: |
set
|
Has patch: |
unset
|
Patch needs improvement: |
unset
|
Summary: |
Model.DoesNotExist classes are not pickleable → Allow pickling dynamically created Model exception classes (DoesNotExist, MultipleObjectsReturned, RelatedObjectDoesNotExist)
|
Resolution: |
→ fixed
|
Status: |
new → closed
|
I've created a patch for this: https://github.com/django/django/pull/9076