mirror of
https://github.com/django/django.git
synced 2025-12-15 21:45:20 +00:00
Fixed #21430 -- Added a RuntimeWarning when unpickling Models and QuerySets from a different Django version.
Thanks FunkyBob for the suggestion, prasoon2211 for the initial patch, and akaariai, loic, and charettes for helping in shaping the patch.
This commit is contained in:
parent
e163a3d17b
commit
42736ac8e8
11 changed files with 210 additions and 16 deletions
|
|
@ -410,6 +410,28 @@ For more details, including how to delete objects in bulk, see
|
|||
If you want customized deletion behavior, you can override the ``delete()``
|
||||
method. See :ref:`overriding-model-methods` for more details.
|
||||
|
||||
Pickling objects
|
||||
================
|
||||
|
||||
When you :mod:`pickle` a model, its current state is pickled. When you unpickle
|
||||
it, it'll contain the model instance at the moment it was pickled, rather than
|
||||
the data that's currently in the database.
|
||||
|
||||
.. admonition:: You can't share pickles between versions
|
||||
|
||||
Pickles of models are only valid for the version of Django that
|
||||
was used to generate them. If you generate a pickle using Django
|
||||
version N, there is no guarantee that pickle will be readable with
|
||||
Django version N+1. Pickles should not be used as part of a long-term
|
||||
archival strategy.
|
||||
|
||||
.. versionadded:: 1.8
|
||||
|
||||
Since pickle compatibility errors can be difficult to diagnose, such as
|
||||
silently corrupted objects, a ``RuntimeWarning`` is raised when you try to
|
||||
unpickle a model in a Django version that is different than the one in
|
||||
which it was pickled.
|
||||
|
||||
.. _model-instance-methods:
|
||||
|
||||
Other model instance methods
|
||||
|
|
|
|||
|
|
@ -116,6 +116,13 @@ described here.
|
|||
Django version N+1. Pickles should not be used as part of a long-term
|
||||
archival strategy.
|
||||
|
||||
.. versionadded:: 1.8
|
||||
|
||||
Since pickle compatibility errors can be difficult to diagnose, such as
|
||||
silently corrupted objects, a ``RuntimeWarning`` is raised when you try to
|
||||
unpickle a queryset in a Django version that is different than the one in
|
||||
which it was pickled.
|
||||
|
||||
.. _queryset-api:
|
||||
|
||||
QuerySet API
|
||||
|
|
|
|||
|
|
@ -176,6 +176,13 @@ Models
|
|||
* Django now logs at most 9000 queries in ``connections.queries``, in order
|
||||
to prevent excessive memory usage in long-running processes in debug mode.
|
||||
|
||||
* Pickling models and querysets across different versions of Django isn't
|
||||
officially supported (it may work, but there's no guarantee). An extra
|
||||
variable that specifies the current Django version is now added to the
|
||||
pickled state of models and querysets, and Django raises a ``RuntimeWarning``
|
||||
when these objects are unpickled in a different version than the one in
|
||||
which they were pickled.
|
||||
|
||||
Signals
|
||||
^^^^^^^
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue