Re: Database race conditions when using multiple processes

2006-10-17 Thread Hawkeye
Michael Radziej wrote: > > What about > SELECT ... FOR UPDATE > ) Michael, I know you're already aware of this (heck, you're CCed on the ticket), but for others... I created a patch in ticket http://code.djangoproject.com/ticket/2705 to allow a .for_update() modifier to be applied to a QuerySet

Re: Re: Database race conditions when using multiple processes

2006-10-17 Thread James Bennett
On 10/17/06, Michael Radziej <[EMAIL PROTECTED]> wrote: > I bet you mean that get_or_create shouldn't lock the table. > That's really not a good idea. I meant Django should never implicitly/automatically lock a table; if you decide you need to lock, you should have to explicitly call something. I

Re: Database race conditions when using multiple processes

2006-10-17 Thread Michael Radziej
James Bennett schrieb: > On 10/17/06, Thomas Steinacher <[EMAIL PROTECTED]> wrote: >> Shouldn't there be a function built-in into Django that locks the table >> (if the database supports it)? IMHO functions like get_or_create() >> should try to lock and unlock the table automatically. > > No, no,

Re: Re: Database race conditions when using multiple processes

2006-10-17 Thread James Bennett
On 10/17/06, Thomas Steinacher <[EMAIL PROTECTED]> wrote: > Shouldn't there be a function built-in into Django that locks the table > (if the database supports it)? IMHO functions like get_or_create() > should try to lock and unlock the table automatically. No, no, a thousand times no :) Even th

Re: Database race conditions when using multiple processes

2006-10-17 Thread Thomas Steinacher
Michael Radziej wrote: > It seems you need to spend more thoughts on multi user issues > within your application. It's easy to fall for that in the > beginning, but you need to deal with concurrent access. You must > be aware for all transactions what impact other transactions can > have. There is

Re: Database race conditions when using multiple processes

2006-10-17 Thread Michael Radziej
Thomas Steinacher schrieb: > James Bennett wrote: >> On 10/16/06, gabor <[EMAIL PROTECTED]> wrote: >>> would you use something in the db? (from what i know about transactions >>> (very little :), they "solve" the potential conflicts by simply >>> reporting an error-condition to one of the "writers

Re: Database race conditions when using multiple processes

2006-10-17 Thread Thomas Steinacher
James Bennett wrote: > On 10/16/06, gabor <[EMAIL PROTECTED]> wrote: > > would you use something in the db? (from what i know about transactions > > (very little :), they "solve" the potential conflicts by simply > > reporting an error-condition to one of the "writers", so then he has to > > retry

Re: Database race conditions when using multiple processes

2006-10-16 Thread gabor
James Bennett wrote: > On 10/16/06, gabor <[EMAIL PROTECTED]> wrote: >> would you use something in the db? (from what i know about transactions >> (very little :), they "solve" the potential conflicts by simply >> reporting an error-condition to one of the "writers", so then he has to >> retry. bu

Re: Re: Database race conditions when using multiple processes

2006-10-16 Thread James Bennett
On 10/16/06, gabor <[EMAIL PROTECTED]> wrote: > would you use something in the db? (from what i know about transactions > (very little :), they "solve" the potential conflicts by simply > reporting an error-condition to one of the "writers", so then he has to > retry. but is there some simply (mul

Re: Database race conditions when using multiple processes

2006-10-16 Thread gabor
James Bennett wrote: > For truly critical > operations, I'd probably just go ahead and grab an exclusive lock on > whatever I needed, and force other transactions to wait. how would you that? would you use something in the db? (from what i know about transactions (very little :), they "solve"

Re: Re: Database race conditions when using multiple processes

2006-10-16 Thread James Bennett
On 10/16/06, Thomas Steinacher <[EMAIL PROTECTED]> wrote: > It did not help with the code I posted that was using get_or_create(), > because I didn't use unique_together... I don't think it would help > with the money-transfer code. This is a tricky problem, not least because each of the DBs we s

Re: Database race conditions when using multiple processes

2006-10-16 Thread gabor
Thomas Steinacher wrote: > gabor wrote: >> Thomas Steinacher wrote: >>> I already included >>> "django.middleware.transaction.TransactionMiddleware" in my >>> MIDDLEWARE_CLASSES (as described on >>> http://www.djangoproject.com/documentation/transactions/#tying-transactions-to-http-requests) >>> a

Re: Database race conditions when using multiple processes

2006-10-16 Thread Thomas Steinacher
gabor wrote: > Thomas Steinacher wrote: > > I already included > > "django.middleware.transaction.TransactionMiddleware" in my > > MIDDLEWARE_CLASSES (as described on > > http://www.djangoproject.com/documentation/transactions/#tying-transactions-to-http-requests) > > and it didn't help. > > > > y

Re: Database race conditions when using multiple processes

2006-10-16 Thread gabor
Thomas Steinacher wrote: > On Oct 16, 2006, at 8:46 PM, gabor wrote: >>> What, if two Django processes transfer money from account A to account >>> B simultaneously? >> these situations are (afaik) handled using transactionssimply start >> a transaction at the beginning, and commit/rollback at

Re: Database race conditions when using multiple processes

2006-10-16 Thread Thomas Steinacher
On Oct 16, 2006, at 8:46 PM, gabor wrote: > > What, if two Django processes transfer money from account A to account > > B simultaneously? > > these situations are (afaik) handled using transactionssimply start > a transaction at the beginning, and commit/rollback at the end... I already incl

Re: Database race conditions when using multiple processes

2006-10-16 Thread Mario Gonzalez ( mario__ )
On 16/10/06, James Bennett <[EMAIL PROTECTED]> wrote: > > SQLite is *not* something to be using if proper locking and safe > concurrent access will be important; SQLite's own docs point out a > couple of cases where its locking just won't work, and they recommend > moving to a client-server RDBMS

Re: Database race conditions when using multiple processes

2006-10-16 Thread James Bennett
On 10/16/06, Thomas Steinacher <[EMAIL PROTECTED]> wrote: > This is my setup: > > - Django (SVN) running with "python manage.py runfcgi method=prefork" > (there are 6 processes running) > - Lighttpd > - SQLite SQLite is *not* something to be using if proper locking and safe concurrent access will

Re: Database race conditions when using multiple processes

2006-10-16 Thread gabor
Thomas Steinacher wrote: > I know that in this specific case it can be enforced at database level > using the unique and unique_together properties, but how would you > handle e.g. this scenario? > > 1 def transfer_money(from_id, to_id, amount) > 2from = models.BankAccount.objects.get(id=fr