Also - get_or_create doesn't always prevent a race condition if you have high traffic.. depending on your code+stack.
I already did a post about this a while back: http://markmail.org/message/j3qr2y26i5uk7c3z On Sat, Jun 23, 2012 at 8:57 AM, Melvyn Sopacua <m.r.sopa...@gmail.com>wrote: > On 23-6-2012 9:52, Melvyn Sopacua wrote: > > On 23-6-2012 0:02, ydjango wrote: > >> > >> Thank you, I also believe it is Race condition. I do not want to use > >> get_or_create as I like to have control over DB writes and updates. I > will > >> try Unique_together and catch the integrity error exception as Kurtis > >> suggested or check again before doing save(). > >> > >> or just thinking aloud, Is there a way to acquire a lock which can > >> serialize any other requests which have same "a" and "b" values? > > > > unique_together + transaction middleware. > > https://docs.djangoproject.com/en/1.4/topics/db/transactions/ > > Ok, hit send too soon. No, this doesn't give you access to other > requests as far as I can tell, but operations depending upon the insert > operation succeeding are now part of a transaction and can be handled > more gracefully inside django as well, pending the result of the > transaction. > > -- > Melvyn Sopacua > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.