Skip to content

Comments

fix: swev-id: django__django-15569 clear lookup cache after unregister#511

Open
casey-brooks wants to merge 2 commits intodjango__django-15569from
noa/issue-505
Open

fix: swev-id: django__django-15569 clear lookup cache after unregister#511
casey-brooks wants to merge 2 commits intodjango__django-15569from
noa/issue-505

Conversation

@casey-brooks
Copy link

Summary

  • clear stale lookup cache entries when a lookup is unregistered so transforms disappear immediately
  • add regression assertions exercising lookup cache invalidation for ForeignObject and functional unique constraints
  • keep constraint teardown inside the temporary registration scope so removal works once the cache is purged

Fixes #505.

Reproduction Steps

  1. cd tests
  2. PYTHONPATH=$PWD:$PWD/.. ../.venv/bin/python runtests.py --parallel 1 custom_lookups.tests.LookupTests.test_lookups_caching
  3. PYTHONPATH=$PWD:$PWD/.. ../.venv/bin/python runtests.py --parallel 1 schema.tests.SchemaTests.test_func_unique_constraint_lookups

Observed Failures

Creating test database for alias 'default'...
Testing against Django installed in '/workspace/django/django'
Found 1 test(s).
System check identified no issues (0 silenced).
F
======================================================================
FAIL: test_lookups_caching (custom_lookups.tests.LookupTests.test_lookups_caching)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/workspace/django/tests/custom_lookups/tests.py", line 327, in test_lookups_caching
    self.assertNotIn("exactly", field.get_lookups())
AssertionError: 'exactly' unexpectedly found in {'in': <class 'django.db.models.fields.related_lookups.RelatedIn'>, 'exact': <class 'django.db.models.fields.related_lookups.RelatedExact'>, 'lt': <class 'django.db.models.fields.related_lookups.RelatedLessThan'>, 'gt': <class 'django.db.models.fields.related_lookups.RelatedGreaterThan'>, 'gte': <class 'django.db.models.fields.related_lookups.RelatedGreaterThanOrEqual'>, 'lte': <class 'django.db.models.fields.related_lookups.RelatedLessThanOrEqual'>, 'isnull': <class 'django.db.models.fields.related_lookups.RelatedIsNull'>, 'exactly': <class 'custom_lookups.tests.Exactly'>}

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (failures=1)
Destroying test database for alias 'default'...
Creating test database for alias 'default'...
Testing against Django installed in '/workspace/django/django'
Found 1 test(s).
System check identified no issues (0 silenced).
F
======================================================================
FAIL: test_func_unique_constraint_lookups (schema.tests.SchemaTests.test_func_unique_constraint_lookups)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/workspace/django/django/test/testcases.py", line 1571, in skip_wrapper
    return test_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/django/tests/schema/tests.py", line 2775, in test_func_unique_constraint_lookups
    self.assertIsNone(name_field.get_transform("lower"))
AssertionError: <class 'django.db.models.functions.text.Lower'> is not None

----------------------------------------------------------------------
Ran 1 test in 0.003s

FAILED (failures=1)
Destroying test database for alias 'default'...

Testing

  • cd tests && PYTHONPATH=$PWD:$PWD/.. ../.venv/bin/python runtests.py --parallel 1 custom_lookups.tests.LookupTests.test_lookups_caching
  • cd tests && PYTHONPATH=$PWD:$PWD/.. ../.venv/bin/python runtests.py --parallel 1 schema.tests.SchemaTests.test_func_unique_constraint_lookups
  • .venv/bin/flake8 django/db/models/query_utils.py
  • .venv/bin/flake8 tests/custom_lookups/tests.py
  • .venv/bin/flake8 --extend-ignore=E721 tests/schema/tests.py

@casey-brooks casey-brooks requested a review from a team December 24, 2025 16:58
@casey-brooks
Copy link
Author

Test & Lint Summary

  • cd tests && PYTHONPATH=/workspace/django:/workspace/django/.. ../.venv/bin/python runtests.py --parallel 1 custom_lookups.tests.LookupTests.test_lookups_caching (1 test, 0 failed)
  • cd tests && PYTHONPATH=/workspace/django:/workspace/django/.. ../.venv/bin/python runtests.py --parallel 1 schema.tests.SchemaTests.test_func_unique_constraint_lookups (1 test, 0 failed)
  • .venv/bin/flake8 django/db/models/query_utils.py (no issues)
  • .venv/bin/flake8 tests/custom_lookups/tests.py (no issues)
  • .venv/bin/flake8 --extend-ignore=E721 tests/schema/tests.py (no issues; E721 ignored to accommodate existing pattern)

Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified the lookup unregister path now clears the cached lookup maps and the new tests exercise the regression for both custom lookups and functional unique constraints. Looks good.

@casey-brooks
Copy link
Author

Test & Lint Summary

  • ../.venv/bin/python runtests.py --parallel 1 custom_lookups.tests.LookupTests.test_lookups_caching: passed (1 test)
  • ../.venv/bin/python runtests.py --parallel 1 schema.tests.SchemaTests.test_func_unique_constraint_lookups: passed (1 test)
  • Linting not requested (not run)

@rowan-stein rowan-stein changed the base branch from django__django-15569 to main January 11, 2026 20:32
@rowan-stein rowan-stein changed the base branch from main to django__django-15569 January 12, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure RegisterLookupMixin._unregister_lookup clears lookup cache; adjust tests (swev-id: django__django-15569)

2 participants