diff options
| author | Simon Charette <charette.s@gmail.com> | 2018-11-23 21:18:47 -0500 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-05-15 20:22:51 +0200 |
| commit | 1dd96f731df3ca9df0e3ff83a9a8e723dc7e8685 (patch) | |
| tree | 2653b60128eed9affb5ed95ba3b7408a3440c560 | |
| parent | 0e3b0da2e3ecee05e8b5eee763f444c94280dbcb (diff) | |
Refs #13227 -- Adjusted a test to avoid making a shared test model unpickable.
This allowed the Note model to be used in setUpTestData() which requires
assigned model instances to be copy.deepcopy()'able.
| -rw-r--r-- | tests/queries/models.py | 9 | ||||
| -rw-r--r-- | tests/queries/tests.py | 5 |
2 files changed, 5 insertions, 9 deletions
diff --git a/tests/queries/models.py b/tests/queries/models.py index fc46205a79..247d4b7671 100644 --- a/tests/queries/models.py +++ b/tests/queries/models.py @@ -1,8 +1,6 @@ """ Various complex queries that have been problematic in the past. """ -import threading - from django.db import models from django.db.models.functions import Now @@ -51,13 +49,6 @@ class Note(models.Model): def __str__(self): return self.note - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - # Regression for #13227 -- having an attribute that - # is unpicklable doesn't stop you from cloning queries - # that use objects of that type as an argument. - self.lock = threading.Lock() - class Annotation(models.Model): name = models.CharField(max_length=10) diff --git a/tests/queries/tests.py b/tests/queries/tests.py index e596c38e76..bf08e7a421 100644 --- a/tests/queries/tests.py +++ b/tests/queries/tests.py @@ -3,6 +3,7 @@ import pickle import sys import unittest from operator import attrgetter +from threading import Lock from django.core.exceptions import EmptyResultSet, FieldError from django.db import DEFAULT_DB_ALIAS, connection @@ -2198,6 +2199,10 @@ class CloneTests(TestCase): n_list = Note.objects.all() # 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): + pickle.dumps(n_list) # Use the note queryset in a query, and evaluate # that query in a way that involves cloning. self.assertEqual(ExtraInfo.objects.filter(note__in=n_list)[0].info, 'good') |
