[Django] #20659: Error in the example for Using SingleObjectMixin with ListView

14 views
Skip to first unread message

Django

unread,
Jun 26, 2013, 5:54:23 AM6/26/13
to django-...@googlegroups.com
#20659: Error in the example for Using SingleObjectMixin with ListView
--------------------------------+--------------------
Reporter: tudor.prodan@… | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 1.5
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------+--------------------
In this section:
https://docs.djangoproject.com/en/1.5/topics/class-based-views/mixins
/#using-singleobjectmixin-with-listview

The example code has a mistake.

Both `SingleObjectMixin.get_object` and `ListView` will use
`self.get_queryset`.
`get_queryset` is overwritten in the example to always return `book_set`,
hence, `get_object` will always fail.

`get_object` does take an optional `queryset` parameter, which, if passed,
will be used instead of `self.get_queryset`, so the example may work if
when calling `get_object`:

{{{
def get(self, request, *args, **kwargs):
- self.object = self.get_object()
+ self.object = self.get_object(queryset=self.model.objects)
return super(PublisherDetail, self).get(request, *args, **kwargs)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20659>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 26, 2013, 8:18:38 AM6/26/13
to django-...@googlegroups.com
#20659: Error in the example for Using SingleObjectMixin with ListView
--------------------------------+------------------------------------
Reporter: tudor.prodan@… | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 1.5
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by bmispelon):

* cc: bmispelon@… (added)
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

I believe I'm the one who introduced this issue with commit
c6862d57c1e987f0f98a77826d19358b9040bad1.

I think the amount of bugs related to this page shows why you should keep
your class-based views simple: it's very hard to anticipate the
interactions of mixins which are not meant to work together.

Thanks for catching this.

--
Ticket URL: <https://code.djangoproject.com/ticket/20659#comment:1>

Django

unread,
Jun 26, 2013, 11:32:28 AM6/26/13
to django-...@googlegroups.com
#20659: Error in the example for Using SingleObjectMixin with ListView
--------------------------------+------------------------------------
Reporter: tudor.prodan@… | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 1.5

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by bmispelon):

* has_patch: 0 => 1


Comment:

I'm starting to wonder if it wouldn't be easier to remove the
`SingleObjectMixin` and just go with `self.object =
get_object_or_404(Publisher, pk=self.kwargs['pk'])` in the `get` method of
the view.

I find it much cleaner but it defeats the purpose of this part of the
documentation.

In any case, here's the patch that fixes the current documentation.

--
Ticket URL: <https://code.djangoproject.com/ticket/20659#comment:2>

Django

unread,
Jun 30, 2013, 11:57:56 PM6/30/13
to django-...@googlegroups.com
#20659: Error in the example for Using SingleObjectMixin with ListView
--------------------------------+------------------------------------
Reporter: tudor.prodan@… | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 1.5

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
--------------------------------+------------------------------------

Comment (by susan):

Baptiste, I've just applied your patch, see PR here:
https://github.com/django/django/pull/1318

--
Ticket URL: <https://code.djangoproject.com/ticket/20659#comment:3>

Django

unread,
Jul 1, 2013, 12:02:29 AM7/1/13
to django-...@googlegroups.com
#20659: Error in the example for Using SingleObjectMixin with ListView
--------------------------------+------------------------------------
Reporter: tudor.prodan@… | Owner: susan
Type: Bug | Status: assigned
Component: Documentation | Version: 1.5

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by susan):

* owner: nobody => susan
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/20659#comment:4>

Django

unread,
Jul 1, 2013, 7:06:54 AM7/1/13
to django-...@googlegroups.com
#20659: Error in the example for Using SingleObjectMixin with ListView
-------------------------------------+-------------------------------------

Reporter: tudor.prodan@… | Owner: susan
Type: Bug | Status: assigned
Component: Documentation | Version: 1.5
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 1 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timo):

* stage: Accepted => Ready for checkin


Comment:

@susan: thanks, but I don't think simply creating pull requests from
patches is necessary (don't want you to waste your time).

Besides a typo ("explicitly") this looks good (although I haven't tested
it).

--
Ticket URL: <https://code.djangoproject.com/ticket/20659#comment:5>

Django

unread,
Jul 1, 2013, 7:11:02 AM7/1/13
to django-...@googlegroups.com
#20659: Error in the example for Using SingleObjectMixin with ListView
-------------------------------------+-------------------------------------
Reporter: tudor.prodan@… | Owner: susan
Type: Bug | Status: assigned
Component: Documentation | Version: 1.5

Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 1 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by tudor.prodan@…):

I've tested it, and it works.

--
Ticket URL: <https://code.djangoproject.com/ticket/20659#comment:6>

Django

unread,
Jul 1, 2013, 8:09:17 AM7/1/13
to django-...@googlegroups.com
#20659: Error in the example for Using SingleObjectMixin with ListView
-------------------------------------+-------------------------------------
Reporter: tudor.prodan@… | Owner: susan
Type: Bug | Status: closed
Component: Documentation | Version: 1.5
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 1 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Baptiste Mispelon <bmispelon@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"88de53d4a86548016f245a1413b856aa334bc737"]:
{{{
#!CommitTicketReference repository=""
revision="88de53d4a86548016f245a1413b856aa334bc737"
Fixed #20659 -- Fixed PublisherDetail in CBV topic documentation.

Thanks to tudor.prodan, susan, and Tim Graham for the report and reviews.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20659#comment:7>

Django

unread,
Jul 1, 2013, 8:11:29 AM7/1/13
to django-...@googlegroups.com
#20659: Error in the example for Using SingleObjectMixin with ListView
-------------------------------------+-------------------------------------
Reporter: tudor.prodan@… | Owner: susan
Type: Bug | Status: closed
Component: Documentation | Version: 1.5

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 1 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Baptiste Mispelon <bmispelon@…>):

In [changeset:"e03a88ba217006fbd7618e3f836c2f6210638aaf"]:
{{{
#!CommitTicketReference repository=""
revision="e03a88ba217006fbd7618e3f836c2f6210638aaf"
[1.6.x] Fixed #20659 -- Fixed PublisherDetail in CBV topic documentation.

Backport of 88de53d4a86548016f245a1413b856aa334bc737 from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20659#comment:8>

Django

unread,
Jan 20, 2014, 5:20:33 PM1/20/14
to django-...@googlegroups.com
#20659: Error in the example for Using SingleObjectMixin with ListView
-------------------------------------+-------------------------------------
Reporter: tudor.prodan@… | Owner: susan
Type: Bug | Status: closed
Component: Documentation | Version: 1.5

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 1 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Baptiste Mispelon <bmispelon@…>):

In [changeset:"0946aac61d0da2aceafe6179cdb64ccad583d924"]:
{{{
#!CommitTicketReference repository=""
revision="0946aac61d0da2aceafe6179cdb64ccad583d924"
[1.5.x] Fixed #20659 -- Fixed PublisherDetail in CBV topic documentation.

Thanks to tudor.prodan, susan, and Tim Graham for the report and reviews.

Backport of 88de53d4a86548016f245a1413b856aa334bc737 from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20659#comment:9>

Reply all
Reply to author
Forward
0 new messages