diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py index 0caa165e151b..6917820604b4 100644 --- a/django/db/models/query_utils.py +++ b/django/db/models/query_utils.py @@ -217,6 +217,7 @@ def _unregister_lookup(cls, lookup, lookup_name=None): 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 1cf99b8300da..943c99f18f76 100644 --- a/tests/custom_lookups/tests.py +++ b/tests/custom_lookups/tests.py @@ -324,6 +324,8 @@ def test_lookups_caching(self): # getting the lookups again should re-cache self.assertIn("exactly", field.get_lookups()) + self.assertNotIn("exactly", field.get_lookups()) + class BilateralTransformTests(TestCase): def test_bilateral_upper(self): diff --git a/tests/schema/tests.py b/tests/schema/tests.py index fa59a3e0b137..68e008cd5bb6 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -2770,16 +2770,20 @@ def test_func_unique_constraint_lookups(self): 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) + name_field = Author._meta.get_field("name") + weight_field = Author._meta.get_field("weight") + self.assertIsNone(name_field.get_transform("lower")) + self.assertIsNone(weight_field.get_transform("abs")) self.assertNotIn(constraint.name, self.get_constraints(table)) @skipUnlessDBFeature("supports_expression_indexes")