Code

Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#13358 closed (fixed)

RelatedManager does not work with db_manager

Reported by: craig.kimerer@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2-beta
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

RelatedManager is always selecting from the db_for_read provided by the router even if db_manager() is used.

With the following models:

class ModelA(models.Model):
  foo = models.IntegerField(default=0)

class ModelB(models.Model):
  bar = models.ManyToManyField(ModelA)

Running the following in shell:

>>> mod_a = ModelA.objects.create(foo=1)
>>> mod_b = ModelB.objects.create()
>>> mod_b.bar.add(mod_a)
>>> mod_a.modelb_set
<django.db.models.fields.related.ManyRelatedManager object at 0x102b4da50
>>> mod_a.modelb_set.db
'default_slave'
>>> mod_a.modelb_set.db_manager('default').db
'default'
>>> mod_a.modelb_set.db_manager('default').all()[0]._state.db
'default_slave'

Attachments (0)

Change History (3)

comment:1 Changed 4 years ago by russellm

  • milestone set to 1.2
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

For the record, it also affects reverse FK relations.

comment:2 Changed 4 years ago by russellm

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

(In [12993]) Fixed #13358 -- Ensured that db_manager() can be used to override database routing on M2M, reverse FK and generic key queries. Thanks to Craig Kimerer for the report.

comment:3 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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.