#16865: get_or_create defaults to _for_write even when it's just reading
-------------------------------------+-------------------------------------
     Reporter:  Rick van Hattem      |                    Owner:  nobody
  <Rick.van.Hattem@…>                |                   Status:  new
         Type:  Bug                  |                  Version:  1.3
    Component:  Database layer       |               Resolution:
  (models, ORM)                      |             Triage Stage:  Accepted
     Severity:  Normal               |      Needs documentation:  0
     Keywords:                       |  Patch needs improvement:  0
    Has patch:  0                    |                    UI/UX:  0
  Needs tests:  0                    |
Easy pickings:  1                    |
-------------------------------------+-------------------------------------

Comment (by kmtracey):

 I think the suggestion here has been misunderstood (at any rate I
 misunderstood it when overhearing part of a conversation about
 it...sorry!) and that the suggested change would not break anything. The
 suggestion is to simply move the `_for_write=True` down to where a write
 is actually going to be attempted. Yes, that means the initial attempt to
 `get` may falsely say "not here!" when in fact the instance has already
 been created in one DB but not propagated to the DB chosen for the initial
 `get` attempt. But the subsequent code that tries the create already
 handles the case where the `create` fails due to the object already
 existing: it re-attempts the `get`, which at that point will query the
 same database as the write was attempted on and will succeed (assuming
 this code works at all, which it doesn't on MySQL/InnoDB with repeatable
 read transaction isolation level, but that's an entirely different
 ticket).

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16865#comment:4>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to