#8419: Fix race in get_or_create() which can lead to update --------------------------------------------------------------+------------- Reporter: Richard Davies <[EMAIL PROTECTED]> | Owner: nobody Status: new | Milestone: 1.0 Component: Database wrapper | Version: SVN Keywords: | Stage: Unreviewed Has_patch: 1 | --------------------------------------------------------------+------------- There is a race condition in get_or_create - if the object is not present for the initial get(), but is swiftly created elsewhere, then the save() will update the object created elsewhere and return it with created=True.
This patch uses save(force_insert=True) to stop this from happening, and to drop through into the existing code that re-attempts the get(). I also update some of the documentation to make the behavior completely clear. Note: Patch follows discussion with Malcolm at http://groups.google.com/group/django- developers/browse_thread/thread/179ed55b3bf44af0/067be6c02aba2bb3?hl=en#067be6c02aba2bb3 I am only submitting the patch to get_or_create(), which seemed uncontroversial. I personally believe that a similar force_insert=True should be used in create(), or if not then at least that force_insert and force_update flags should be available for create() as well as for save(). -- Ticket URL: <http://code.djangoproject.com/ticket/8419> Django Code <http://code.djangoproject.com/> The web framework for perfectionists with deadlines --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---
