Opened 12 years ago

Closed 12 years ago

#16048 closed Bug (fixed)

GenericForeignKey always uses a default manager of a related model

Reported by: Ivan Virabyan Owned by: nobody
Component: contrib.contenttypes Version: 1.3
Severity: Normal Keywords: genericforeignkey manager
Cc: me@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

From Django docs:
By default, Django uses an instance of a "plain" manager class when accessing related objects (i.e. choice.poll), not the default manager on the related object. This is because Django needs to be able to retrieve the related object, even if it would otherwise be filtered out (and hence be inaccessible) by the default manager.

This is true for ForeignKey, but not GenericForeignKey. So I have no ability to use custom managers for my models, because they are being filtered when I'm accessing related objects.

Attachments (1)

ticket16048-r16259.diff (2.4 KB) - added by Andy Durdin 12 years ago.
Patch against trunk revision 16259

Download all attachments as: .zip

Change History (8)

comment:1 Changed 12 years ago by Andy Durdin

Owner: changed from nobody to Andy Durdin
Status: newassigned

Changed 12 years ago by Andy Durdin

Attachment: ticket16048-r16259.diff added

Patch against trunk revision 16259

comment:2 Changed 12 years ago by Andy Durdin

Has patch: set
Owner: changed from Andy Durdin to nobody
Status: assignednew
Triage Stage: UnreviewedAccepted

A straightforward bug both to test and fix. Patch with tests and fix attached.

comment:3 Changed 12 years ago by Andy Durdin

Cc: Andy Durdin added

comment:4 Changed 12 years ago by Dougal Matthews

Triage Stage: AcceptedReady for checkin

Looks good.

comment:5 Changed 12 years ago by Andy Durdin

Cc: Andy Durdin removed

comment:6 Changed 12 years ago by Andy Durdin

Cc: me@… added

comment:7 Changed 12 years ago by Jannis Leidel

Resolution: fixed
Status: newclosed

In [16261]:

Fixed #16048 -- Use the base manager instead of the default manager to retrieve a related object of a GenericForeignKey similar to ForeignKeys. Thanks, adurdin.

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