Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#28575 closed Bug (fixed)

Allow pickling dynamically created Model exception classes (DoesNotExist, MultipleObjectsReturned, RelatedObjectDoesNotExist)

Reported by: Rachel Tobin Owned by: nobody
Component: Database layer (models, ORM) Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

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)

comment:1 by Rachel Tobin, 7 years ago

Type: UncategorizedBug

comment:2 by Rachel Tobin, 7 years ago

Description: modified (diff)

comment:3 by Tim Graham, 7 years ago

Description: modified (diff)
Triage Stage: UnreviewedAccepted

comment:4 by Rachel Tobin, 7 years ago

Has patch: set

I've created a patch for this: https://github.com/django/django/pull/9077

Last edited 7 years ago by Rachel Tobin (previous) (diff)

comment:5 by Tim Graham, 7 years ago

Patch needs improvement: set

comment:6 by Tim Graham <timograham@…>, 7 years ago

In 6c92f711:

Refs #28575 -- Allowed pickling Model.DoesNotExist and MultipleObjectsReturned classes.

comment:7 by Tim Graham, 7 years ago

Has patch: unset
Patch needs improvement: unset
Summary: Model.DoesNotExist classes are not pickleableAllow pickling dynamically created Model exception classes (DoesNotExist, MultipleObjectsReturned, RelatedObjectDoesNotExist)

The ticket remains open to allow pickling RelatedObjectDoesNotExist which according to Simon, "will require a lot more work."

comment:9 by Tim Graham <timograham@…>, 7 years ago

In 216eda1:

Refs #28575 -- Removed unnecessary code for model exception pickling.

Setting qualname is sufficient for pickling of DoesNotExist and
and MultipleObjectsReturned to work correctly.

comment:10 by Tim Graham <timograham@…>, 7 years ago

In d4fb7420:

Refs #28575 -- Made RelatedObjectDoesNotExist classes pickable.

Thanks to Rachel Tobin for the initial qualname work and tests.

comment:11 by Tim Graham, 7 years ago

Resolution: fixed
Status: newclosed

comment:12 by Frankie Dintino, 6 years ago

Are there any plans to backport this patch to Django 1.11?

Version 0, edited 6 years ago by Frankie Dintino (next)
Note: See TracTickets for help on using tickets.
Back to Top