mirror of https://github.com/django/django.git
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 unittest
|
||||
from operator import attrgetter
|
||||
from threading import Lock
|
||||
|
||||
from django.core.exceptions import EmptyResultSet, FieldError, FullResultSet
|
||||
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):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
|
@ -2571,8 +2575,8 @@ class CloneTests(TestCase):
|
|||
# Evaluate the Note queryset, populating the query cache
|
||||
list(n_list)
|
||||
# Make one of cached results unpickable.
|
||||
n_list._result_cache[0].lock = Lock()
|
||||
with self.assertRaises(TypeError):
|
||||
n_list._result_cache[0].error = UnpickleableError()
|
||||
with self.assertRaises(UnpickleableError):
|
||||
pickle.dumps(n_list)
|
||||
# Use the note queryset in a query, and evaluate
|
||||
# that query in a way that involves cloning.
|
||||
|
|
Loading…
Reference in New Issue