Opened 12 years ago
Closed 11 years ago
#18853 closed Bug (duplicate)
get_template_names() does not consider the queryset-only case
Reported by: | Melvyn Sopacua | Owned by: | Florian Apolloner |
---|---|---|---|
Component: | Generic views | Version: | dev |
Severity: | Normal | Keywords: | CBV |
Cc: | jason@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | yes | UI/UX: | no |
Description
In SingleObjectTemplateResponseMixin candidate names are generated using the model name. This model name is derived either from self.object or self.model but does not consider self.queryset. In the case of "create forms", self.object is unset and if self.model is not provided either, an exception is thrown much later by the template loader in select_template. This exception does not point to this method as it successfully returns an (empty) list.
The test suite kind of contains a test for this (generic_views/edit.py:test_create_without_redirect), but the problem is that the test posts data to the form and does not actually request the form. In the practical case this form could never have been submitted as it wouldn't be rendered.
Patch attached fixes the issue and creates a test.
Attachments (1)
Change History (10)
by , 12 years ago
Attachment: | django-bug-template-names-with-queryset.patch added |
---|
follow-up: 2 comment:1 by , 12 years ago
IMHO replacing the hasattr(self, 'queryset') and self.queryset is not None
part by getattr(self, 'queryset', None) is not None
would increase readability.
comment:2 by , 12 years ago
Replying to charettes:
IMHO replacing the
hasattr(self, 'queryset') and self.queryset is not None
part bygetattr(self, 'queryset', None) is not None
would increase readability.
Agreed, but it's inline with the coding style of the file, see line 150 right above. Style fixes are the committers' realm. ;)
comment:3 by , 12 years ago
Cc: | added |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
Patch applies cleanly. Test fails before applying fix. Test passes after applying fix.
comment:4 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Triage Stage: | Accepted → Ready for checkin |
comment:5 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
comment:6 by , 12 years ago
#16502 is a similar problem. I guess patch there may also fix this problem.
comment:7 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:8 by , 11 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Ready for checkin → Accepted |
Patch no longer applies cleanly.
comment:9 by , 11 years ago
Resolution: | → duplicate |
---|---|
Status: | assigned → closed |
This is a duplicate of #16502. Please see that issue for resolution of this problem.
Fix and testcase