Bug 247053 - IDBObjectStore.put() deletes object on unique index violation
Summary: IDBObjectStore.put() deletes object on unique index violation
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Website Storage (show other bugs)
Version: Safari 16
Hardware: Mac (Intel) macOS 12
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-10-26 02:18 PDT by David Fahlander
Modified: 2022-11-02 02:19 PDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Fahlander 2022-10-26 02:18:50 PDT
Calling IDBObjectStore.put(object) resulting in a constraint violation, should leave the database as if the operation did not take place, but if the operation fails due to a violation of a unique index, the end result will be a deletion of the object.

Repro link: https://jsitor.com/0oBx-UC93

The repro has an object store "users" with primary key "id" and unique index on property "username".
First, it adds two objects in the object store:

{id: 1, username: "foo"}
{id: 2, username: "bar"}

Then, it does a put operation with {id: 1, username: "bar"}, which would violate the uniqueness of the username index because "bar" is already occupied by the second object (with id 2).

After that transaction has ended (auto-committed), the repro will list all users in the database and only find the second entry.
Comment 1 Radar WebKit Bug Importer 2022-11-02 02:19:17 PDT
<rdar://problem/101850333>