Opened 3 years ago
Last modified 3 years ago
#33626 closed Cleanup/optimization
django.db.models.query_utils.RegisterLookupMixin._unregister_lookup method also should clear the cache stored for django.db.models.query_utils.RegisterLookupMixin.get_lookups — at Version 2
Reported by: | Himanshu Balasamanta | Owned by: | Himanshu Balasamanta |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 4.0 |
Severity: | Normal | Keywords: | Lookups, caching, ORM |
Cc: | Carlton Gibson | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Hi Carlton.
I have opened the PR https://github.com/django/django/pull/15569, and have also modified the test that was supposed to throw error(schema.tests.SchemaTests.test_func_unique_constraint_lookups).
There is no test that checks if the lookup stays in cache after unregistering it. In my PR, I have added an assert statement to check it in custom_lookups.tests.LookupTests.test_lookups_caching test. Running the test without clearing cache from _unregister_lookup will fail.
The cache stays between tests, so you are likely to get different results running tests independently and running all tests in a module. (PS: I faced this problem earlier running tests individually and together gave different results.)
Hi Himanshu. This may be right, yes — I need to have a sit-down and play with it.
Main question: Are you able to put together an example case where the wrong result arrises?
For use in tests only...
in the_unregister_lookup
docstring. So this would show up in a test inter-dependency...? 🤔