#26253 closed Bug (fixed)
Deprecation for TemplateResponse and SimpleTemplateResponse accepting django.template.Template is broken
Reported by: | David Reitter | Owned by: | Tim Graham |
---|---|---|---|
Component: | Template system | Version: | 1.8 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
When TemplateResponse
or SimpleTemplateResponse
are called, a TypeError is thrown.
This is because their __init__() creates a
BackendTemplate` giving only one argument to the constructor.
The resulting error is obviously confusing and obfuscates the warning.
The attached patch addresses the issue, although I am unsure whether one should assume, by default, that a DjangoTemplate was given.
Attachments (1)
Change History (12)
by , 9 years ago
Attachment: | response.patch added |
---|
comment:1 by , 9 years ago
Description: | modified (diff) |
---|---|
Summary: | TemplateResponse and BasicTemplateResponse: error message causes TypeError → TemplateResponse and SimpleTemplateResponse: error message causes TypeError |
comment:2 by , 9 years ago
Yes, that change of yours is correct (my mistake).
The code that caused it is really quite simple. It just makes a TemplateResponse based on Template without the engine. This came up because I transitioned a Django 1.5 project to 1.9.
The code that produces the exception seems to be meant to handle outdated code like this.
from django.template import Template from django.template.response import TemplateResponse def results(request): content = "…" t = Template(content) return TemplateResponse(request, t)
comment:3 by , 9 years ago
Keywords: | Teamplates removed |
---|---|
Needs tests: | set |
Severity: | Normal → Release blocker |
Summary: | TemplateResponse and SimpleTemplateResponse: error message causes TypeError → Deprecation for TemplateResponse and SimpleTemplateResponse accepting django.template.Template is broken |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
Version: | 1.9 → 1.8 |
Oh, I had trouble understanding your patch and the problem. The issue is that the backwards compatibility shim crashes. If you are able to add tests for the patch and send a pull request, that would be great.
from django.template import Template from django.template.response import TemplateResponse from django.http import HttpRequest request = HttpRequest() content = "…" t = Template(content) response = TemplateResponse(request, t) ... File "/home/tim/code/django/django/template/response.py", line 28, in __init__ template = BackendTemplate(template) TypeError: __init__() missing 1 required positional argument: 'backend'
comment:4 by , 9 years ago
Sorry, I looked into writing a test and pretty much got stuck with what seemed to be the test scripts running the system install of Django rather than the code in the checkout.
I won’t have the time to submit more than the patch I submitted, due to various professional obligations. Apologies.
comment:5 by , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:7 by , 9 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Can you provide code to reproduce the issue? I'm not entirely clear on it based on the description. Is the issue relevant on master or only in 1.9 that has the deprecation path? If only 1.9, the problem may not be severe enough to warrant being patched there.
I edited the description to change
BaseTemplateResponse
toSimpleTemplateResponse
since there's no class in Django with the former name. Please edit again if it should be something else.