summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimanshu-Balasamanta <himanshubb.eee18@itbhu.ac.in>2022-04-08 15:21:51 +0530
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-04-12 06:24:02 +0200
commit06ebaa9e287137d4496a2736b055f1c6aed95839 (patch)
treeed6f120b3dc2138413517d827b0f5aa6bde569fa
parent884b4c27f506b3c29d58509fc83a35c30ea10d94 (diff)
Fixed #33626 -- Cleared cache when unregistering a lookup.
-rw-r--r--django/db/models/query_utils.py1
-rw-r--r--tests/custom_lookups/tests.py2
-rw-r--r--tests/model_fields/test_jsonfield.py1
-rw-r--r--tests/schema/tests.py20
4 files changed, 13 insertions, 11 deletions
diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py
index 0caa165e15..6917820604 100644
--- a/django/db/models/query_utils.py
+++ b/django/db/models/query_utils.py
@@ -217,6 +217,7 @@ class RegisterLookupMixin:
if lookup_name is None:
lookup_name = lookup.lookup_name
del cls.class_lookups[lookup_name]
+ cls._clear_cached_lookups()
def select_related_descend(field, restricted, requested, load_fields, reverse=False):
diff --git a/tests/custom_lookups/tests.py b/tests/custom_lookups/tests.py
index 1cf99b8300..ece67a46a5 100644
--- a/tests/custom_lookups/tests.py
+++ b/tests/custom_lookups/tests.py
@@ -323,6 +323,8 @@ class LookupTests(TestCase):
with register_lookup(models.ForeignObject, Exactly):
# getting the lookups again should re-cache
self.assertIn("exactly", field.get_lookups())
+ # Unregistration should bust the cache.
+ self.assertNotIn("exactly", field.get_lookups())
class BilateralTransformTests(TestCase):
diff --git a/tests/model_fields/test_jsonfield.py b/tests/model_fields/test_jsonfield.py
index 38c92fc518..60cc694843 100644
--- a/tests/model_fields/test_jsonfield.py
+++ b/tests/model_fields/test_jsonfield.py
@@ -88,7 +88,6 @@ class TestMethods(SimpleTestCase):
transform = field.get_transform("my_transform")
self.assertIs(transform, MyTransform)
models.JSONField._unregister_lookup(MyTransform)
- models.JSONField._clear_cached_lookups()
transform = field.get_transform("my_transform")
self.assertIsInstance(transform, KeyTransformFactory)
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index fa59a3e0b1..d56e820251 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -2770,16 +2770,16 @@ class SchemaTests(TransactionTestCase):
with connection.schema_editor() as editor:
editor.add_constraint(Author, constraint)
sql = constraint.create_sql(Author, editor)
- table = Author._meta.db_table
- constraints = self.get_constraints(table)
- self.assertIn(constraint.name, constraints)
- self.assertIs(constraints[constraint.name]["unique"], True)
- # SQL contains columns.
- self.assertIs(sql.references_column(table, "name"), True)
- self.assertIs(sql.references_column(table, "weight"), True)
- # Remove constraint.
- with connection.schema_editor() as editor:
- editor.remove_constraint(Author, constraint)
+ table = Author._meta.db_table
+ constraints = self.get_constraints(table)
+ self.assertIn(constraint.name, constraints)
+ self.assertIs(constraints[constraint.name]["unique"], True)
+ # SQL contains columns.
+ self.assertIs(sql.references_column(table, "name"), True)
+ self.assertIs(sql.references_column(table, "weight"), True)
+ # Remove constraint.
+ with connection.schema_editor() as editor:
+ editor.remove_constraint(Author, constraint)
self.assertNotIn(constraint.name, self.get_constraints(table))
@skipUnlessDBFeature("supports_expression_indexes")