Re: get_or_create not atomic?

2009-05-13 Thread Elliott
On May 12, 12:47 pm, Phil Mocek <pmocek-list-django-us...@mocek.org> wrote: > On Tue, May 12, 2009 at 02:25:41AM -0700, Daniel Roseman wrote: > > No, [get_or_create is] not atomic. You can see the code in > > django.db.models.query - it tries a db lookup, and then creates &g

Re: get_or_create not atomic?

2009-05-12 Thread Malcolm Tredinnick
On Tue, 2009-05-12 at 10:47 -0700, Phil Mocek wrote: > On Tue, May 12, 2009 at 02:25:41AM -0700, Daniel Roseman wrote: > > No, [get_or_create is] not atomic. By the way, that depends on what grained-ness of atomicity you're after, which hasn't been defined in this thread. The

Re: get_or_create not atomic?

2009-05-12 Thread George Song
On 5/12/2009 10:47 AM, Phil Mocek wrote: > It seems risky to try to handle at the > application level these things that a DBMS is specifically > designed to do. Well, exactly. If the correct constraints are put in place, then your DB/adaptor would raise the proper error. So if a row is

Re: get_or_create not atomic?

2009-05-12 Thread Phil Mocek
On Tue, May 12, 2009 at 02:25:41AM -0700, Daniel Roseman wrote: > No, [get_or_create is] not atomic. You can see the code in > django.db.models.query - it tries a db lookup, and then creates > a new object if one is not found. It seems that this creates a potentially-troublesome race

Re: get_or_create not atomic?

2009-05-12 Thread Daniel Roseman
On May 12, 10:04 am, Will McGugan wrote: > Hi, > > I recently tracked down a strange bug in our site where 2 object existed but > the code was expecting only one. > > I think this is due to get_or_create, which doesn't appear to be atomic. > What I assume happened is that

get_or_create not atomic?

2009-05-12 Thread Will McGugan
Hi, I recently tracked down a strange bug in our site where 2 object existed but the code was expecting only one. I think this is due to get_or_create, which doesn't appear to be atomic. What I assume happened is that two requests came in close together and tested for the existence of the object

Re: get_or_create isn't atomic?

2007-03-29 Thread Malcolm Tredinnick
et_or_create is an exception. And I'm guessing lots of > other people already know this. You're right. The get_or_create() call isn't atomic, because it isn't a single database call and we cannot assume that the database layer has transactions (because it's not universally true). The window of opportunit

Re: get_or_create isn't atomic?

2007-03-29 Thread Frankie Robertson
On 29/03/07, John Penix <[EMAIL PROTECTED]> wrote: > > I think I saw a get_or_create race condition today from concurrent > runs of our data uploader that uses the model API. Ouch. The docs > have several references to the api calls being atomic - now I'm > thinking get_or_create is an

get_or_create isn't atomic?

2007-03-28 Thread John Penix
I think I saw a get_or_create race condition today from concurrent runs of our data uploader that uses the model API. Ouch. The docs have several references to the api calls being atomic - now I'm thinking get_or_create is an exception. And I'm guessing lots of other people already know this.