[Django] #34707: AttributeError: 'function' object has no attribute 'cache_clear' when registering a custom lookup

46 views
Skip to first unread message

Django

unread,
Jul 11, 2023, 11:24:46 AM7/11/23
to django-...@googlegroups.com
#34707: AttributeError: 'function' object has no attribute 'cache_clear' when
registering a custom lookup
---------------------------------------------+------------------------
Reporter: Justin Michalicek | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 4.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
Going from the documentation at
https://docs.djangoproject.com/en/4.1/howto/custom-lookups/#a-lookup-
example, 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 manage.py runserver 0.0.0.0:8000
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/threading.py", line 1038, in
_bootstrap_inner
self.run()
File "/app/.venv/lib/python3.11/site-
packages/sentry_sdk/integrations/threading.py", line 72, in run
reraise(*_capture_exception())
File "/app/.venv/lib/python3.11/site-packages/sentry_sdk/_compat.py",
line 60, in reraise
raise value
File "/app/.venv/lib/python3.11/site-
packages/sentry_sdk/integrations/threading.py", line 70, in run
return old_run_func(self, *a, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "/app/.venv/lib/python3.11/site-
packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/app/.venv/lib/python3.11/site-
packages/django/core/management/commands/runserver.py", line 125, in
inner_run
autoreload.raise_last_exception()
File "/app/.venv/lib/python3.11/site-
packages/django/utils/autoreload.py", line 87, in raise_last_exception
raise _exception[1]
File "/app/.venv/lib/python3.11/site-
packages/django/core/management/__init__.py", line 398, in execute
autoreload.check_errors(django.setup)()
File "/app/.venv/lib/python3.11/site-
packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/app/.venv/lib/python3.11/site-packages/django/__init__.py", line
24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/app/.venv/lib/python3.11/site-packages/django/apps/registry.py",
line 124, in populate
app_config.ready()
File "/app/app/my_project/core/apps.py", line 13, in ready
Field.register_lookup(NotEqual)
File "/app/.venv/lib/python3.11/site-
packages/django/db/models/query_utils.py", line 256, in register_lookup
cls._clear_cached_lookups()
File "/app/.venv/lib/python3.11/site-
packages/django/db/models/query_utils.py", line 247, in
_clear_cached_lookups
subclass.get_lookups.cache_clear()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'function' object has no attribute 'cache_clear'
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34707>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 11, 2023, 12:42:36 PM7/11/23
to django-...@googlegroups.com
#34707: AttributeError: 'function' object has no attribute 'cache_clear' when
registering a custom lookup
-----------------------------------+--------------------------------------

Reporter: Justin Michalicek | Owner: nobody
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 4.1
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by David Sanders):

* status: new => closed
* resolution: => invalid


Comment:

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: https://www.djangoproject.com/community/ You'll
need

--
Ticket URL: <https://code.djangoproject.com/ticket/34707#comment:1>

Reply all
Reply to author
Forward
0 new messages