indexeddb put() error : index uniqueness requirement

1,453 views
Skip to first unread message

tech4computer

unread,
Jan 3, 2012, 9:56:49 PM1/3/12
to Chromium-discuss
Hi,

I'm getting following error on store.put(obj) :
"One of the derived (from a keyPath) keys for an index does not
satisfy its uniqueness requirements."

The 'obj' contains the original 'id' (e.g. obj.id=5) and an updated
property e.g. obj.test="new value".
The keypath is an autoincrement id.

The store.put(obj) used to work fine, but stopped working sometime
ago.

Thx

Joshua Bell

unread,
Jan 3, 2012, 11:36:16 PM1/3/12
to tech4c...@gmail.com, Chromium-discuss
That error should only be returned if the object store has an index with a unique constraint (pretty much what the error reports). Can you check the indexes on the store to see if that might explain what you're seeing?


--
Chromium Discussion mailing list: chromium...@chromium.org
View archives, change email options, or unsubscribe:
   http://groups.google.com/a/chromium.org/group/chromium-discuss

tech4computer

unread,
Jan 4, 2012, 1:35:01 AM1/4/12
to Chromium-discuss
Yes there is one property with index set to unique. I'm not changing
that property though. I'm changing/adding a new property to the object
and I have not created index for this property in objectstore.

var store = db.createObjectStore(
"storeName",
{keyPath: "id", autoIncrement: true}
);
....
store.createIndex("property1", "property1", { unique: true })
store.createIndex("property2", "property2", { unique: false })
....
store.add({'property1' : 'a', 'property2 : 'b'})
....
store.put({ id:5, 'property1' : 'a', 'property2' : 'b',
'newProperty' : 'test' })

On Jan 3, 8:36 pm, Joshua Bell <jsb...@chromium.org> wrote:
> That error should only be returned if the object store has an index with a
> unique constraint (pretty much what the error reports). Can you check the
> indexes on the store to see if that might explain what you're seeing?
>
> On Tue, Jan 3, 2012 at 6:56 PM, tech4computer <tech4compu...@gmail.com>wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I'm getting following error on store.put(obj) :
> > "One of the derived (from a keyPath) keys for an index does not
> > satisfy its uniqueness requirements."
>
> > The 'obj' contains the original 'id' (e.g. obj.id=5) and an updated
> > property e.g. obj.test="new value".
> > The keypath is an autoincrement id.
>
> > The store.put(obj) used to work fine, but stopped working sometime
> > ago.
>
> > Thx
>
> > --
> > Chromium Discussion mailing list: chromium-disc...@chromium.org

Joshua Bell

unread,
Jan 4, 2012, 1:47:30 PM1/4/12
to tech4c...@gmail.com, Chromium-discuss
On Tue, Jan 3, 2012 at 10:35 PM, tech4computer <tech4c...@gmail.com> wrote:
Yes there is one property with index set to unique. I'm not changing
that property though. I'm changing/adding a new property to the object
and I have not created index for this property in objectstore.

var store = db.createObjectStore(
 "storeName",
  {keyPath: "id", autoIncrement: true}
);
....
store.createIndex("property1", "property1", { unique: true })
store.createIndex("property2", "property2", { unique: false })
....
store.add({'property1' : 'a', 'property2 : 'b'})
....
store.put({ id:5, 'property1' : 'a', 'property2' : 'b',
'newProperty' : 'test' })

I realize that's sample code, but with the data given above I'd expect it to fail. The added record will end up with an autogenerated id (e.g. 0); the put record's property1 value "a" will fail the second index's uniqueness test. If I run a test and specify either id: 5 for the added record or a different property1 value for the put it succeeds.

I'm guessing that in practice you're adding records that don't so obviously fail the constraint and may be hitting a bug in Chrome - can you extend that to a stand alone test case that repros the issue and file a bug at crbug.com ? I'll email you my test files off-list.
 
On Jan 3, 8:36 pm, Joshua Bell <jsb...@chromium.org> wrote:
> That error should only be returned if the object store has an index with a
> unique constraint (pretty much what the error reports). Can you check the
> indexes on the store to see if that might explain what you're seeing?
>
> On Tue, Jan 3, 2012 at 6:56 PM, tech4computer <tech4compu...@gmail.com>wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I'm getting following error on store.put(obj) :
> > "One of the derived (from a keyPath) keys for an index does not
> > satisfy its uniqueness requirements."
>
> > The 'obj' contains the original 'id' (e.g. obj.id=5) and an updated
> > property e.g. obj.test="new value".
> > The keypath is an autoincrement id.
>
> > The store.put(obj) used to work fine, but stopped working sometime
> > ago.
>
> > Thx
>
> > --
> > Chromium Discussion mailing list: chromium-disc...@chromium.org
> > View archives, change email options, or unsubscribe:
> >    http://groups.google.com/a/chromium.org/group/chromium-discuss

--
Chromium Discussion mailing list: chromium...@chromium.org
Reply all
Reply to author
Forward
0 new messages