Skip to content

django-template-partials and the templates panel do not work well together it seems #2109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
matthiask opened this issue Mar 19, 2025 · 3 comments · Fixed by #2117
Closed
Assignees

Comments

@matthiask
Copy link
Member

Loading template sources crashes:

[19/Mar/2025 11:06:46] "GET /__debug__/render_panel/?store_id=f32af068303746c588911011cbf7da3f&panel_id=TemplatesPanel HTTP/1.1" 200 249515
Internal Server Error: /__debug__/template_source/
Traceback (most recent call last):
  File ".../.venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../projects/django-debug-toolbar/debug_toolbar/decorators.py", line 34, in inner
    return view(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../projects/django-debug-toolbar/debug_toolbar/decorators.py", line 46, in inner
    return view(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../projects/django-debug-toolbar/debug_toolbar/panels/templates/views.py", line 45, in template_source
    source = loader.get_contents(origin)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.12/site-packages/django/template/loaders/cached.py", line 27, in get_contents
    return origin.loader.get_contents(origin)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get_contents'

(The strange debug toolbar paths are there because I use an editable install)

@tim-schilling
Copy link
Member

I wonder if this is related to how django-cotton and django-template-partials don't play nicely together and require some extra setup. https://django-cotton.com/docs/django-template-partials

@matthiask
Copy link
Member Author

We have some code in here to handle cached loaders:

for loader in loaders:
if loader is not None:
# When the loader has loaders associated with it,
# append those loaders to the list. This occurs with
# django.template.loaders.cached.Loader
if hasattr(loader, "loaders"):
final_loaders += loader.loaders
else:
final_loaders.append(loader)

Template partials does more wrapping of loaders:
https://github.com/carltongibson/django-template-partials/blob/b0c0879b0cde74f152df85256b2619d937a4cfd8/src/template_partials/apps.py#L37

I suspect it has something to do with loaders not being determined correctly or something, but I don't really know. I spent some time on it and didn't find a quick fix (I instead switched to a different project to test the template panel which doesn't use template partials.)

matthiask added a commit to matthiask/django-debug-toolbar that referenced this issue Mar 31, 2025
@matthiask
Copy link
Member Author

I have now worked on this a bit because it has bitten me again tonight.

The change works but lacks tests and docs.

matthiask added a commit to matthiask/django-debug-toolbar that referenced this issue Mar 31, 2025
@matthiask matthiask self-assigned this Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants