This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 16441 - Spec should note that onsuccess shouldn’t be used for writes.
Summary: Spec should note that onsuccess shouldn’t be used for writes.
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: Indexed Database API (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: This bug has no owner yet - up for the taking
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-19 20:12 UTC by Yonathan Randolph
Modified: 2012-07-16 21:49 UTC (History)
5 users (show)

See Also:


Attachments

Description Yonathan Randolph 2012-03-19 20:12:35 UTC
You generally should listen to the transaction’s “complete” event instead of the put/add request’s “success” event, because the transaction may fail after “success.” There’s at least one example of someone being confused by the wording[1]. Perhaps the spec should point out that you usually want to listen to “complete” for write requests.

Use of a write request’s “success”/“error” events is probably reserved for advanced use cases (e.g. to commit part of a transaction even when the later requests fail, or to retry a write that failed, or to measure progress when a transaction has multiple parts).

 [1]: https://developer.mozilla.org/en/IndexedDB/Using_IndexedDB
Comment 1 Jonas Sicking (Not reading bugmail) 2012-07-16 00:40:02 UTC
Note that there are cases where listening for onsuccess is needed. For example if you are worried that a written entry might collide with an already existing one. In this case you might want to hold off further operations until the doubtful request has succeeded.
Comment 2 Eliot Graff 2012-07-16 21:49:56 UTC
Added this note to Transaction.oncomplete and also for IDBObjectstore.add().

To determine if a transaction has completed successfully, listen to the transaction’s complete event rather than the IDBObjectStore.add request’s success event, because the transaction may still fail after the success event fires.