mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Refs #34986 -- Avoided implementation-specific unpickleable types.
The implementation of some core types differ between CPython and PyPy and this may affect the way that pickling works such that errors are raised in differing locations in the interpreter or not at all. Use our own custom non-pickleable type instead to avoid these quirks.
This commit is contained in:
parent
2c6e4a29b0
commit
1c3614e306
@ -3,7 +3,6 @@ import pickle
|
|||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
from threading import Lock
|
|
||||||
|
|
||||||
from django.core.exceptions import EmptyResultSet, FieldError, FullResultSet
|
from django.core.exceptions import EmptyResultSet, FieldError, FullResultSet
|
||||||
from django.db import DEFAULT_DB_ALIAS, connection
|
from django.db import DEFAULT_DB_ALIAS, connection
|
||||||
@ -113,6 +112,11 @@ from .models import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class UnpickleableError(Exception):
|
||||||
|
def __reduce__(self):
|
||||||
|
raise type(self)("Cannot pickle.")
|
||||||
|
|
||||||
|
|
||||||
class Queries1Tests(TestCase):
|
class Queries1Tests(TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
@ -2571,8 +2575,8 @@ class CloneTests(TestCase):
|
|||||||
# Evaluate the Note queryset, populating the query cache
|
# Evaluate the Note queryset, populating the query cache
|
||||||
list(n_list)
|
list(n_list)
|
||||||
# Make one of cached results unpickable.
|
# Make one of cached results unpickable.
|
||||||
n_list._result_cache[0].lock = Lock()
|
n_list._result_cache[0].error = UnpickleableError()
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(UnpickleableError):
|
||||||
pickle.dumps(n_list)
|
pickle.dumps(n_list)
|
||||||
# Use the note queryset in a query, and evaluate
|
# Use the note queryset in a query, and evaluate
|
||||||
# that query in a way that involves cloning.
|
# that query in a way that involves cloning.
|
||||||
|
Loading…
Reference in New Issue
Block a user