Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#26006 closed Cleanup/optimization (fixed)

SingleObjectMixin.get_context_object_name refers to obj and self.object inconsistently

Reported by: Chris Cogdon Owned by: Chris Cogdon
Component: Generic views Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The method SingleObjectMixin.get_context_object_name refers to the 'obj' parameter several times, but in one instance refers to self.object in a seemingly inconsistent manner.

This is probably not causing a problem, yet, since the descendant class, typically BaseDetailView, is setting self.object, and SingleObjectMixin.get_context_data simply calls self.get_context_object_name(self.object), so the two are _usually_ the same object.

Trivial bug, and trivial fix. I'll create a pull request. Test suite passes both before and after the change.

Change History (9)

comment:1 Changed 3 years ago by Chris Cogdon

Pull request: https://github.com/django/django/pull/5890

All tests pass under SQLite.

comment:2 Changed 3 years ago by Chris Cogdon

Has patch: set
Owner: changed from nobody to Chris Cogdon
Status: newassigned

comment:3 Changed 3 years ago by Chris Cogdon

Triage Stage: UnreviewedAccepted

comment:4 Changed 3 years ago by Simon Charette

Needs tests: set
Patch needs improvement: set
Version: 1.9master

The change makes sense.

This should be good to go once you add a regression test or adjust the ones added by this check.

comment:5 Changed 3 years ago by Chris Cogdon

Thank you for the link to the changes. I'll set up a test case.

comment:6 Changed 3 years ago by Chris Cogdon

Needs tests: unset
Patch needs improvement: unset

Pull request updated: https://github.com/django/django/pull/5890

Unit test added. Release notes updated. Still passes all tests. Documentation compiles without error.

comment:7 Changed 3 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 4b2dcfe:

Fixed #26006 -- Fixed incorrect object reference in SingleObjectMixin.get_context_object_name().

comment:8 Changed 3 years ago by Tim Graham <timograham@…>

In 4d9b986:

[1.9.x] Fixed #26006 -- Fixed incorrect object reference in SingleObjectMixin.get_context_object_name().

Backport of 4b2dcfe04f5d9938e40c569ffdd169f3a712145d from master

comment:9 Changed 3 years ago by Chris Cogdon

My first commit! I am so proud! 😺

Also, I see you caught the extraneous dot in the release notes. Almost nothing gets by you!

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