tickets: 8419
This data as json
id | created | changetime | last_pulled_from_trac | stage | status | component | type | severity | version | resolution | summary | description | owner | reporter | keywords | easy | has_patch | needs_better_patch | needs_tests | needs_docs | ui_ux |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
8419 | 2008-08-19 15:43:17 | 2011-09-28 16:12:17 | 2022-03-06 03:42:12.965336 | Design decision needed | closed | Database layer (models, ORM) | dev | fixed | Fix race in get_or_create() which can lead to update | 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(). | nobody | Richard Davies <richard.davies@elastichosts.com> | 0 | 1 | 0 | 0 | 0 | 0 |