#36817 closed Bug (duplicate)
Possible regression of Engine.get_template
| Reported by: | Henrik Ossipoff Hansen | Owned by: | Varun Kasyap Pentamaraju |
|---|---|---|---|
| Component: | Template system | Version: | 6.0 |
| Severity: | Normal | Keywords: | |
| Cc: | Carlton Gibson | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
While trying to upgrade to Django 6.0 locally today, we noticed an issue with one of our third party packages, adminsortable2.
For their admin templates, they use Path objects: https://github.com/jrief/django-admin-sortable2/blob/master/adminsortable2/admin.py#L124
This has worked until this commit https://github.com/django/django/commit/5e06b970956af4854e970e74990cb971ba31c96b where get_template was refactored to support Template Partials.
As a by-product, template names now have to be strings.
I don't see that it was ever mentioned/officially supported, to use Path objects for templates, but I would suspect that several third party libraries does this, and I would therefore see this as a regression.
If this is deemed not to be the case, I'll create an issue on their Github to change the behaviour.
Change History (7)
comment:1 by , 4 days ago
comment:2 by , 4 days ago
| Cc: | added |
|---|---|
| Severity: | Normal → Release blocker |
| Triage Stage: | Unreviewed → Accepted |
Yes… OK. The DTL loader always expected strings, but they're always meant to be paths, so Path objects seem a reasonable thing to allow.
Checking if template_name is a Path and converting back to a string in get_template() should be acceptable.
Want to make a PR Henrik?
comment:3 by , 3 days ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
follow-up: 5 comment:4 by , 3 days ago
Can see Varun assigned themselves, so I'll let them handle it - if not I'll gladly make quick-fix.
comment:5 by , 3 days ago
| Has patch: | set |
|---|
Thanks Henrik,
Created Patch: https://github.com/django/django/pull/20442
comment:6 by , 3 days ago
| Has patch: | unset |
|---|---|
| Resolution: | → duplicate |
| Severity: | Release blocker → Normal |
| Status: | assigned → closed |
| Triage Stage: | Accepted → Unreviewed |
Thanks, but this was wontfixed in #36817. The provided patch doesn't account for the jinja2 loader, for example, so we shouldn't suggest this is supported.
For their admin templates, they use Path objects:
Are you sure you haven't updated to a more recent version of that package? The source you linked to shows this was already fixed there.
TypeError at /admin/terminals/terminal/ sequence item 0: expected str instance, PosixPath found Request Method: GET Request URL: http://localhost:8000/admin/terminals/terminal/ Django Version: 6.0 Exception Type: TypeError Exception Value: sequence item 0: expected str instance, PosixPath found Exception Location: /usr/local/lib/python3.14/site-packages/django/template/loader.py, line 47, in select_template Raised during: adminsortable2.admin.changelist_view Python Executable: /usr/local/bin/python Python Version: 3.14.2 Python Path: ['/code', '/code', '/usr/local/lib/python314.zip', '/usr/local/lib/python3.14', '/usr/local/lib/python3.14/lib-dynload', '/usr/local/lib/python3.14/site-packages'] Server time: Mon, 22 Dec 2025 08:54:07 +0000 Traceback Switch to copy-and-paste view /usr/local/lib/python3.14/site-packages/django/core/handlers/exception.py, line 55, in inner response = get_response(request) ^^^^^^^^^^^^^^^^^^^^^ … Local vars /usr/local/lib/python3.14/site-packages/django/core/handlers/base.py, line 221, in _get_response response = response.render() ^^^^^^^^^^^^^^^^^ … Local vars /usr/local/lib/python3.14/site-packages/django/template/response.py, line 114, in render self.content = self.rendered_content ^^^^^^^^^^^^^^^^^^^^^ … Local vars /usr/local/lib/python3.14/site-packages/django/template/response.py, line 90, in rendered_content template = self.resolve_template(self.template_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ … Local vars /usr/local/lib/python3.14/site-packages/django/template/response.py, line 72, in resolve_template return select_template(template, using=self.using) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ … Local vars /usr/local/lib/python3.14/site-packages/django/template/loader.py, line 47, in select_template raise TemplateDoesNotExist(", ".join(template_name_list), chain=chain) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ … Local vars