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)

django-bug-template-names-with-queryset.patch (2.7 KB ) - added by Melvyn Sopacua 12 years ago.
Fix and testcase

Download all attachments as: .zip

Change History (10)

by Melvyn Sopacua, 12 years ago

Fix and testcase

comment:1 by Simon Charette, 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.

in reply to:  1 comment:2 by Melvyn Sopacua, 12 years ago

Replying to charettes:

IMHO replacing the hasattr(self, 'queryset') and self.queryset is not None part by getattr(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 Jason Mayfield, 12 years ago

Cc: jason@… added
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Patch applies cleanly. Test fails before applying fix. Test passes after applying fix.

comment:4 by Jason Mayfield, 12 years ago

Owner: changed from nobody to Jason Mayfield
Status: newassigned
Triage Stage: AcceptedReady for checkin

comment:5 by Jason Mayfield, 12 years ago

Owner: changed from Jason Mayfield to nobody
Status: assignednew

comment:6 by bhuztez, 12 years ago

#16502 is a similar problem. I guess patch there may also fix this problem.

comment:7 by Florian Apolloner, 11 years ago

Owner: changed from nobody to Florian Apolloner
Status: newassigned

comment:8 by Tim Graham, 11 years ago

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

Patch no longer applies cleanly.

comment:9 by jambonrose, 11 years ago

Resolution: duplicate
Status: assignedclosed

This is a duplicate of #16502. Please see that issue for resolution of this problem.

Note: See TracTickets for help on using tickets.
Back to Top