Opened 14 years ago

Closed 8 years ago

#13793 closed Bug (fixed)

reverse of OneToOne relation should use default manager if use_for_related_fields specified

Reported by: Shaun Cutts Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2
Severity: Normal Keywords: use_for_related_fields
Cc: shaun@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no


When retrieving the related object in a reverse OneToOne relation, the SingleRelatedObjectDescriptor doesn't respect "use_for_related_fields" if defined by the default manager for the class of the related object. See patch for proposed fix (which indicates the code in question as well).

Attachments (1)

one_to_one_use_default_manager_if_asked.diff (1.0 KB ) - added by Shaun Cutts 14 years ago.
patch for SingleRelatedObjectDescriptor

Download all attachments as: .zip

Change History (9)

by Shaun Cutts, 14 years ago

patch for SingleRelatedObjectDescriptor

comment:1 by Russell Keith-Magee, 14 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Graham King, 13 years ago

Severity: Normal
Type: Bug

comment:3 by Julien Phalip, 13 years ago

Needs tests: set

comment:4 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:5 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:6 by Tim Graham, 8 years ago

Keywords: use_for_related_fields added

comment:7 by Loic Bistuer, 8 years ago

PR6175 deprecates use_for_related_fields. "to-one" relations go through _base_manager which can be specified with the base_manager_name model option.

comment:8 by Loïc Bistuer <loic.bistuer@…>, 8 years ago

Resolution: fixed
Status: newclosed

In ed0ff91:

Fixed #10506, #13793, #14891, #25201 -- Introduced new APIs to specify models' default and base managers.

This deprecates use_for_related_fields.

Old API:

class CustomManager(models.Model):

use_for_related_fields = True

class Model(models.Model):

custom_manager = CustomManager()

New API:

class Model(models.Model):

custom_manager = CustomManager()

class Meta:

base_manager_name = 'custom_manager'

Refs #20932, #25897.

Thanks Carl Meyer for the guidance throughout this work.
Thanks Tim Graham for writing the docs.

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