|Re: select_for_update running on db_for_read||Ioan Alexandru Cucu||2/18/13 7:42 AM|
The correct patch would be:
(Set _for_write on the cloned object rather than the original...)
@@ -664,6 +664,7 @@ class QuerySet(object):
# Default to false for nowait
nowait = kwargs.pop('nowait', False)
obj = self._clone()
+ obj._for_write = True
obj.query.select_for_update = True
obj.query.select_for_update_nowait = nowait
|Re: select_for_update running on db_for_read||Shai Berger||2/19/13 11:23 AM|
On Monday 18 February 2013, Ioan Alexandru Cucu wrote:
> If I'm running a select_for_update statement in a multidb environment that
> uses a read-only slave database
Why does this operation make sense?
Why would you select-for-update if you don't intend to update? Or does
updating on a read-only slave somehow make sense?
|Re: select_for_update running on db_for_read||Ioan Alexandru Cucu||2/19/13 11:44 PM|
Well that's what I'm saying. It doesn't make any sense.
By default, django runs the select_for_update query on the 'for read' database instead of running it on the 'for write' database.
In order to make my code not to break, I need to explicitly tell django that I want the query to run on the 'for write' database.
=> I need to write:
pages = Page.objects.select_for_update().using(router.db_for_write(Page)).all()
instead of just
pages = Page.objects.select_for_update().all()
If I don't add the 'using(router.db_for_write(Page)' I get the traceback mentioned in my initial message.
|Re: select_for_update running on db_for_read||Russell Keith-Magee||2/19/13 11:58 PM|
I'd need to dig into the code to be 100% certain, but what you've described seems plausible, and the fix looks like it's going in the right direction. A ticket is certainly called for.
As for the patch -- it needs tests :-)
Django's test suite has support for testing multiple-database situations; check the regressiontests/multiple_database test suite for examples of how to use it. SELECT_FOR_UPDATE has it's own test suite - modeltests/select_for_update - so the tests probably belong in there.
Russ Magee %-)
On Mon, Feb 18, 2013 at 10:59 PM, Ioan Alexandru Cucu <alexandru...@gmail.com> wrote:
|Re: select_for_update running on db_for_read||Ioan Alexandru Cucu||2/26/13 2:02 AM|