Opened 3 years ago

Closed 3 years ago

#20234 closed Bug (fixed)

SingleObjectMixin does not add 'object' key to context

Reported by: dracos Owned by: elektrrrus
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


The documentation at 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:

Change History (6)

comment:1 Changed 3 years ago by dracos

  • Component changed from Uncategorized to Generic views
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 3 years ago by tinodb

  • Cc tinodb added
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Bug

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 3 years ago by mjtamlyn

  • 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 3 years ago by MarkusH

  • Owner changed from nobody to MarkusH
  • Status changed from new to assigned

comment:5 Changed 3 years ago by elektrrrus

  • Owner changed from MarkusH to elektrrrus

I'will resolve this ticket together with #20236.

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

  • Resolution set to fixed
  • Status changed from assigned to closed

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