From 1c3614e306e80d5a57c52d36c2a1868e1e5f9ab3 Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Tue, 21 Nov 2023 15:11:58 +0000 Subject: [PATCH] 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. --- tests/queries/tests.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/queries/tests.py b/tests/queries/tests.py index 20665ab2cd..48d610bb2b 100644 --- a/tests/queries/tests.py +++ b/tests/queries/tests.py @@ -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.