Race condition in Model.save() with non-automatic unique indexes
|Reported by:||hfaber@…||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.0|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The current Model.save() implementation transparently handles updating of records vs. insertion of new records.
It first tries to update an existing record and if it fails it will do an insert instead.
This can lead to a race condition when between the failed update and the subsequent insert another process successfully inserts an object with the same primary key (or other field with unique index). For automatically generated primary keys (e.g. auto-inc IDs) this is not a problem. But for manually-set PKs (or other unique fields) this will lead to a key integrity violation.
Change History (3)
comment:1 Changed 7 years ago by mrts
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Resolution set to duplicate
- Status changed from new to closed
comment:2 Changed 7 years ago by mrts
- Resolution duplicate deleted
- Status changed from closed to reopened