#32965: Django related manager allways choose db_for_read router and fail
update/delete
-------------------------------------+-------------------------------------
     Reporter:  Regressor            |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  3.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:  related manager,     |             Triage Stage:
  db_for_read, exception, db,        |  Unreviewed
  router                             |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Adrian Torres):

 Replying to [comment:1 Mariusz Felisiak]:
 > Thanks for this report, however IMO it's not a bug. It's
 [https://docs.djangoproject.com/en/3.2/topics/db/multi-db/#selecting-a
 -database-to-delete-from documented] that `DELETE` will be executed on the
 same database that was used to retrieve the object, so you need to use
 `using`. I would recommend to use related manager's methods i.e. `clear()`
 instead of chaining `all()` and `delete()`, e.g.
 `instance.mentor_binds.clear()`, and `set()` instead of `update()`, e.g.
 `instance.mentor_binds.set(...)`.

 Hi Mariusz, is there a reason as to why it is done so? While I understand
 that it's documented, it's not intuitive and is an easy pit to fall into.
 I'd be willing to submit a backwards-compatible patch if the reason is not
 "it's impossible" :)

 Cheers
-- 
Ticket URL: <https://code.djangoproject.com/ticket/32965#comment:3>
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 view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019a6e4e347d-ce8bdb07-6301-443a-a76b-e82672f1bbc9-000000%40eu-central-1.amazonses.com.

Reply via email to