Opened 6 years ago

Closed 5 months 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 6 years ago.
patch for SingleRelatedObjectDescriptor

Download all attachments as: .zip

Change History (9)

Changed 6 years ago by Shaun Cutts

patch for SingleRelatedObjectDescriptor

comment:1 Changed 6 years ago by Russell Keith-Magee

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

comment:2 Changed 6 years ago by Graham King

Severity: Normal
Type: Bug

comment:3 Changed 6 years ago by Julien Phalip

Needs tests: set

comment:4 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:5 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:6 Changed 6 months ago by Tim Graham

Keywords: use_for_related_fields added

comment:7 Changed 5 months ago by Loic Bistuer

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 Changed 5 months ago by Loïc Bistuer <loic.bistuer@…>

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