Opened 4 years ago

Closed 4 years ago

#20234 closed Bug (fixed)

SingleObjectMixin does not add 'object' key to context

Reported by: Matthew Somerville Owned by: Karol Sikora
Component: Generic views Version: master
Severity: Normal Keywords:
Cc: tinodb, marc.tamlyn@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The documentation at https://docs.djangoproject.com/en/dev/ref/class-based-views/mixins-single-object/#django.views.generic.detail.SingleObjectMixin says that 'object' will be in the context, as well as potentially context_object_name if given. However, actually only context_object_name is set in the context by this mixin; only if object is passed to the mixin (which BaseDetailView does) will it be included.

The MultipleObjectMixin does include 'object_list' in its get_context_data (though assumes it must be passed in rather than on the object, I'll file that as another ticket), so I assume this is an issue with SingleObjectMixin, and that it should set 'object' on context whether it is passed in as a kwarg or not.

I have a patch on a branch of my github fork: https://github.com/dracos/django/compare/singleobjectfixin

Change History (6)

comment:1 Changed 4 years ago by Matthew Somerville

Component: UncategorizedGeneric views

If this ticket is applied, then I think get_context_data of ModelFormMixin becomes entirely superfluous - see ticket #20236.

comment:2 Changed 4 years ago by tinodb

Cc: tinodb added
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Hmm, all "object" stuff does not seem to be very consistent (like you mention in your other tickets).

It also strikes me as strange, that these mixins rely on self.object being set, while it is only set in it's derived classes (that is probably why object was passed as a kwarg earlier).

comment:3 Changed 4 years ago by Marc Tamlyn

Cc: marc.tamlyn@… added

I think the documented functionality is the correct functionality and this and #20236 can be fairly easily tidied up together.

comment:4 Changed 4 years ago by Markus Holtermann

Owner: changed from nobody to Markus Holtermann
Status: newassigned

comment:5 Changed 4 years ago by Karol Sikora

Owner: changed from Markus Holtermann to Karol Sikora

I'will resolve this ticket together with #20236.

comment:6 Changed 4 years ago by Karol Sikora <elektrrrus@…>

Resolution: fixed
Status: assignedclosed

In 3eba8c7f7fc4877e7df0f83fe3bacd88082ac33e:

Fixed #20234 and #20236 -- SingleObjectMixin fixes

Added object on SingleObjectMixin returned context,
some code clanup.

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