Opened 3 months ago

Closed 5 weeks 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 (11)

comment:1 Changed 3 months ago by Rachel Tobin

Type: UncategorizedBug

comment:2 Changed 3 months ago by Rachel Tobin

Description: modified (diff)

comment:3 Changed 2 months ago by Tim Graham

Description: modified (diff)
Triage Stage: UnreviewedAccepted

comment:4 Changed 2 months ago by Rachel Tobin

Has patch: set

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

Last edited 2 months ago by Rachel Tobin (previous) (diff)

comment:5 Changed 8 weeks ago by Tim Graham

Patch needs improvement: set

comment:6 Changed 6 weeks ago by Tim Graham <timograham@…>

In 6c92f711:

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

comment:7 Changed 6 weeks ago by Tim Graham

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:8 Changed 6 weeks ago by Simon Charette

Has patch: set

comment:9 Changed 6 weeks ago by Tim Graham <timograham@…>

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 Changed 5 weeks ago by Tim Graham <timograham@…>

In d4fb7420:

Refs #28575 -- Made RelatedObjectDoesNotExist classes pickable.

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

comment:11 Changed 5 weeks ago by Tim Graham

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top