#17520: write queries on related managers use the db_for_read database
-------------------------------------+-------------------------------------
     Reporter:  tobias               |                    Owner:  slafs
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  1.3
  (models, ORM)                      |               Resolution:
     Severity:  Normal               |             Triage Stage:  Accepted
     Keywords:                       |      Needs documentation:  0
    Has patch:  0                    |  Patch needs improvement:  1
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by slafs):

 The problem seems to be very subtle. The thing is that the `update` method
 on queryset is using `self.db` which uses `self._db` to determine the
 database. When we have a related manager, the queryset from it comes with
 "polluted" `_db`
 
([https://github.com/django/django/blob/dc8814bf7dc5139f3d11b8f9f44f54c7f77d2714/django/db/models/fields/related.py#L407,L408
 because of this] ).

 When i tried a simplest approach with cleaning the _db after getting the
 `qs` like this:
 {{{
 if self._db is None:
     qs._db = None
 }}}

 it turns out that there's some feature tests that gets broken. For example
 
[https://github.com/django/django/blob/dc8814bf7dc5139f3d11b8f9f44f54c7f77d2714/tests/multiple_database/tests.py#L426
 this] (which I think isn't documented anywhere). Will try to propose
 something different.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/17520#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to