Opened 6 years ago
Closed 5 years ago
#30453 closed Cleanup/optimization (fixed)
Django's template library tags cant use already decorated things like lru_cache because of getfullargspec
Reported by: | Batuhan Taşkaya | Owned by: | Batuhan Taşkaya |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Django's template library tags cant use already decorated things like lru_cache because of getfullargspec. I have a tag that requires to be lru_cached but i cant use it without an helper.
The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/lib64/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib64/python3.7/threading.py", line 865, in run self._target(*self._args, **self._kwargs) File "/home/batuhan/.local/share/virtualenvs/aspava-SBPNYCrJ/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper fn(*args, **kwargs) File "/home/batuhan/.local/share/virtualenvs/aspava-SBPNYCrJ/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run self.check(display_num_errors=True) File "/home/batuhan/.local/share/virtualenvs/aspava-SBPNYCrJ/lib/python3.7/site-packages/django/core/management/base.py", line 390, in check include_deployment_checks=include_deployment_checks, File "/home/batuhan/.local/share/virtualenvs/aspava-SBPNYCrJ/lib/python3.7/site-packages/django/core/management/base.py", line 377, in _run_checks return checks.run_checks(**kwargs) File "/home/batuhan/.local/share/virtualenvs/aspava-SBPNYCrJ/lib/python3.7/site-packages/django/core/checks/registry.py", line 72, in run_checks new_errors = check(app_configs=app_configs) File "/home/batuhan/.local/share/virtualenvs/aspava-SBPNYCrJ/lib/python3.7/site-packages/django/contrib/admin/checks.py", line 79, in check_dependencies for engine in engines.all(): File "/home/batuhan/.local/share/virtualenvs/aspava-SBPNYCrJ/lib/python3.7/site-packages/django/template/utils.py", line 90, in all return [self[alias] for alias in self] File "/home/batuhan/.local/share/virtualenvs/aspava-SBPNYCrJ/lib/python3.7/site-packages/django/template/utils.py", line 90, in <listcomp> return [self[alias] for alias in self] File "/home/batuhan/.local/share/virtualenvs/aspava-SBPNYCrJ/lib/python3.7/site-packages/django/template/utils.py", line 81, in __getitem__ engine = engine_cls(params) File "/home/batuhan/.local/share/virtualenvs/aspava-SBPNYCrJ/lib/python3.7/site-packages/django/template/backends/django.py", line 25, in __init__ options['libraries'] = self.get_templatetag_libraries(libraries) File "/home/batuhan/.local/share/virtualenvs/aspava-SBPNYCrJ/lib/python3.7/site-packages/django/template/backends/django.py", line 43, in get_templatetag_libraries libraries = get_installed_libraries() File "/home/batuhan/.local/share/virtualenvs/aspava-SBPNYCrJ/lib/python3.7/site-packages/django/template/backends/django.py", line 108, in get_installed_libraries for name in get_package_libraries(pkg): File "/home/batuhan/.local/share/virtualenvs/aspava-SBPNYCrJ/lib/python3.7/site-packages/django/template/backends/django.py", line 121, in get_package_libraries module = import_module(entry[1]) File "/home/batuhan/.local/share/virtualenvs/aspava-SBPNYCrJ/lib/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1006, in _gcd_import File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 728, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/home/batuhan/qubic/aspava/social/templatetags/renderer.py", line 25, in <module> @lru_cache(None) File "/home/batuhan/.local/share/virtualenvs/aspava-SBPNYCrJ/lib/python3.7/site-packages/django/template/library.py", line 132, in simple_tag return dec(func) File "/home/batuhan/.local/share/virtualenvs/aspava-SBPNYCrJ/lib/python3.7/site-packages/django/template/library.py", line 109, in dec params, varargs, varkw, defaults, kwonly, kwonly_defaults, _ = getfullargspec(func) File "/usr/lib64/python3.7/inspect.py", line 1132, in getfullargspec raise TypeError('unsupported callable') from ex TypeError: unsupported callable
It can be solved with unwrapping the function like templates/base.py did.
Change History (4)
comment:1 by , 5 years ago
Resolution: | → needsinfo |
---|---|
Status: | assigned → closed |
comment:2 by , 5 years ago
Resolution: | needsinfo |
---|---|
Status: | closed → new |
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/optimization |
Version: | 2.2 → master |
I think the issue is well explained through the PR submitted by the author
https://github.com/django/django/pull/11334
re-opening.
Note:
See TracTickets
for help on using tickets.
I'm guessing the answer here may well just be "use a helper" — i.e. structure your code so that you can cache the output, but...
There's not enough to go on here. Please show the minimal example that you think should work.