Opened 8 months ago

Closed 8 months ago

Last modified 8 months ago

#34707 closed Uncategorized (invalid)

AttributeError: 'function' object has no attribute 'cache_clear' when registering a custom lookup

Reported by: Justin Michalicek Owned by: nobody
Component: Uncategorized Version: 4.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Going from the documentation at, I created the custom lookup exactly as shown there. I then registered it in an AppConfig.ready(). When django starts I get the exception AttributeError: 'function' object has no attribute 'cache_clear'.

python runserver
timestamp=None level=None event='Watching for file changes with StatReloader' logger=None
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/", line 1038, in _bootstrap_inner
  File "/app/.venv/lib/python3.11/site-packages/sentry_sdk/integrations/", line 72, in run
  File "/app/.venv/lib/python3.11/site-packages/sentry_sdk/", line 60, in reraise
    raise value
  File "/app/.venv/lib/python3.11/site-packages/sentry_sdk/integrations/", line 70, in run
    return old_run_func(self, *a, **kw)
  File "/usr/local/lib/python3.11/", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "/app/.venv/lib/python3.11/site-packages/django/utils/", line 64, in wrapper
    fn(*args, **kwargs)
  File "/app/.venv/lib/python3.11/site-packages/django/core/management/commands/", line 125, in inner_run
  File "/app/.venv/lib/python3.11/site-packages/django/utils/", line 87, in raise_last_exception
    raise _exception[1]
  File "/app/.venv/lib/python3.11/site-packages/django/core/management/", line 398, in execute
  File "/app/.venv/lib/python3.11/site-packages/django/utils/", line 64, in wrapper
    fn(*args, **kwargs)
  File "/app/.venv/lib/python3.11/site-packages/django/", line 24, in setup
  File "/app/.venv/lib/python3.11/site-packages/django/apps/", line 124, in populate
  File "/app/app/my_project/core/", line 13, in ready
  File "/app/.venv/lib/python3.11/site-packages/django/db/models/", line 256, in register_lookup
  File "/app/.venv/lib/python3.11/site-packages/django/db/models/", line 247, in _clear_cached_lookups
AttributeError: 'function' object has no attribute 'cache_clear'

Change History (1)

comment:1 by David Sanders, 8 months ago

Resolution: invalid
Status: newclosed

Registering custom lookups in an app config's ready works ok for me. You may need to paste copies of your code/setup to show how you're registering it.

Additionally you can seek help from a wider audience using one of the Django support channels:

Last edited 8 months ago by David Sanders (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top