Note that *instances* of `Model.DoesNotExist` are pickleable as fixed
here: https://code.djangoproject.com/ticket/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`.
This could be fixed by changing the metaclass that is used here:
https://github.com/django/django/blob/1.11.5/django/db/models/base.py#L76
to use a custom metaclass with a `__reduce__` method. A patch is in
progress for this.
--
Ticket URL: <https://code.djangoproject.com/ticket/28575>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* type: Uncategorized => Bug
--
Ticket URL: <https://code.djangoproject.com/ticket/28575#comment:1>
Old description:
> 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
> }}}
>
> Note that *instances* of `Model.DoesNotExist` are pickleable as fixed
> here: https://code.djangoproject.com/ticket/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`.
>
> This could be fixed by changing the metaclass that is used here:
> https://github.com/django/django/blob/1.11.5/django/db/models/base.py#L76
> to use a custom metaclass with a `__reduce__` method. A patch is in
> progress for this.
New description:
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
}}}
Note that *instances* of `Model.DoesNotExist` are pickleable as fixed
here: https://code.djangoproject.com/ticket/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`.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/28575#comment:2>
* stage: Unreviewed => Accepted
Old description:
> 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
> }}}
>
> Note that *instances* of `Model.DoesNotExist` are pickleable as fixed
> here: https://code.djangoproject.com/ticket/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`.
New description:
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`.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/28575#comment:3>
* has_patch: 0 => 1
Comment:
I've created a patch for this: https://github.com/django/django/pull/9076
--
Ticket URL: <https://code.djangoproject.com/ticket/28575#comment:4>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/28575#comment:5>
Comment (by Tim Graham <timograham@…>):
In [changeset:"6c92f711eaf382113e811e43900f4fabd0f95c26" 6c92f711]:
{{{
#!CommitTicketReference repository=""
revision="6c92f711eaf382113e811e43900f4fabd0f95c26"
Refs #28575 -- Allowed pickling Model.DoesNotExist and
MultipleObjectsReturned classes.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28575#comment:6>
* needs_better_patch: 1 => 0
* has_patch: 1 => 0
Comment:
The ticket remains open to allow pickling `RelatedObjectDoesNotExist`
which according to Simon, "will require a lot more work."
--
Ticket URL: <https://code.djangoproject.com/ticket/28575#comment:7>
* has_patch: 0 => 1
Comment:
https://github.com/django/django/pull/9239
--
Ticket URL: <https://code.djangoproject.com/ticket/28575#comment:8>
Comment (by Tim Graham <timograham@…>):
In [changeset:"216eda103bee71725b26421e578705f24e17dae0" 216eda1]:
{{{
#!CommitTicketReference repository=""
revision="216eda103bee71725b26421e578705f24e17dae0"
Refs #28575 -- Removed unnecessary code for model exception pickling.
Setting __qualname__ is sufficient for pickling of DoesNotExist and
and MultipleObjectsReturned to work correctly.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28575#comment:9>
Comment (by Tim Graham <timograham@…>):
In [changeset:"d4fb742094dba99cb0db17f3aa9d9f5159af676f" d4fb7420]:
{{{
#!CommitTicketReference repository=""
revision="d4fb742094dba99cb0db17f3aa9d9f5159af676f"
Refs #28575 -- Made RelatedObjectDoesNotExist classes pickable.
Thanks to Rachel Tobin for the initial __qualname__ work and tests.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28575#comment:10>
* status: new => closed
* resolution: => fixed
--
Ticket URL: <https://code.djangoproject.com/ticket/28575#comment:11>
Comment (by Frankie Dintino):
Are there any plans to backport this patch to Django 1.11?
--
Ticket URL: <https://code.djangoproject.com/ticket/28575#comment:12>