Hi,

I'm trying to atomically check if a certain field in the db exists and
create it otherwise. I naively started using get_or_create but it
seems like that function does not try to do things atomically at all.
My database is MySQL and my table type is InnoDB. I installed the
select_for_update patch and was calling
select_for_update().get_or_create():

Tag.objects.select_for_update().get_or_create(name = tagName)

This gave me a deadlock when run from multiple threads. I also tried
select_for_update().get() with a try except on DoesNotExist and then
calling create separately:

try:
        Tag.objects.select_for_update().get(name = tagName)
except Tag.DoesNotExist:
        Tag.objects.create(name = tagName)

I still get a deadlock. It appears that MySQL does not create the
exclusive lock on the row in Tag because it does not exist yet. Is
there a good way (simple or not) of performing this operation
(get_or_create) atomically, even if it is MySQL specific.

I appreciate any help!

Thanks,
Can Sar


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to