Code

Opened 3 years ago

Closed 3 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:

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 adurdin 3 years ago.
Patch against trunk revision 16259

Download all attachments as: .zip

Change History (8)

comment:1 Changed 3 years ago by adurdin

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to adurdin
  • Patch needs improvement unset
  • Status changed from new to assigned

Changed 3 years ago by adurdin

Patch against trunk revision 16259

comment:2 Changed 3 years ago by adurdin

  • Has patch set
  • Owner changed from adurdin to nobody
  • Status changed from assigned to new
  • Triage Stage changed from Unreviewed to Accepted

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

comment:3 Changed 3 years ago by adurdin

  • Cc adurdin added

comment:4 Changed 3 years ago by d0ugal

  • Triage Stage changed from Accepted to Ready for checkin

Looks good.

comment:5 Changed 3 years ago by adurdin

  • Cc adurdin removed

comment:6 Changed 3 years ago by adurdin

  • Cc me@… added

comment:7 Changed 3 years ago by jezdez

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

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.