#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: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by trbs):
* cc: v.oostveen@… (added)
Comment:
Isn't this patch a bit more complicated then it's need to be ?
When we just move down {{{ self._for_write = True }}} from the outer most
try-except one level then we would have the same effect right ?
It will try:
- a read from the slave (or whatever choice is made by the router)
- try to insert the new record on the master
- retry the get operation but this time from the master explicitly since
self._for_write is set.
And we save doing second get() on the master since it would make sense
that most of the time the slaves are up-to-date and so that there is no
master record.
The drawback of that approach is that a transaction is made and executed
in the case that the slave was lagging and the object already exists.
(this could easily happen in a situation where a context processes or
something is executing some code that does the get_or_create and when the
page loads you request multiple pages doing the same get_or_create. First
request actually creates the object but the slaves have not caught up a ms
later that the other request for the same page come in. If you have a high
traffic site you might want to safe on transactions and opt for more
selects instead.)
--
Ticket URL: <https://code.djangoproject.com/ticket/16865#comment:8>
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.