Skip to content

Instantly share code, notes, and snippets.

@theeluwin
Created April 12, 2013 15:15
Show Gist options
  • Select an option

  • Save theeluwin/5372769 to your computer and use it in GitHub Desktop.

Select an option

Save theeluwin/5372769 to your computer and use it in GitHub Desktop.
race condition problem
class Info(models.Model):
itemCount = models.PositiveIntegerField(default = 0)
class Item(models.Model):
name = models.CharField(max_length = 40)
def foo(info, name):
try: item = Item.objects.get(name = name)
except:
item = Item(name = name)
item.save()
info.itemCount += 1
info.save()
return item
@theeluwin
Copy link
Copy Markdown
Author

실제 상황에선 get_or_create를 사용 할 수 없는 상황입니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment