Opened 15 years ago

Closed 15 years ago

Last modified 13 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: no UI/UX: no

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'

Change History (3)

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

milestone: 1.2
Triage Stage: UnreviewedAccepted

For the record, it also affects reverse FK relations.

comment:2 by Russell Keith-Magee, 15 years ago

Resolution: fixed
Status: newclosed

(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 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

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