Ticket #12579: 12579.diff

File 12579.diff, 970 bytes (added by vijay_shanker, 12 years ago)

added a paragraph referring get_or_create concurrency issue

  • querysets.txt

     
    13361336created and the key already exists in the database, an
    13371337:exc:`~django.db.IntegrityError` will be raised.
    13381338
     1339The ``get_or_create()`` method is not atomic.So if unique/unique together is not
     1340implemented on fields used in :meth:`get()` call at database level,
     1341concurrent calls to ``get_or_create()`` method end up creating duplicate objects in database.
     1342If a unique/unique together is implemented, multiple threads can get to the point of save() where
     1343one thread successfully creates the object while the others raise :exc:`~django.db.IntegrityError`.
     1344
    13391345Finally, a word on using ``get_or_create()`` in Django views. As mentioned
    13401346earlier, ``get_or_create()`` is mostly useful in scripts that need to parse
    13411347data and create new records if existing ones aren't available. But if you need
Back to Top