Dexie.js icon indicating copy to clipboard operation
Dexie.js copied to clipboard

Failed to execute 'objectStore' on 'IDBTransaction': The transaction has finished

Open jawalkwan opened this issue 2 years ago • 18 comments

code: 11 message: "Failed to execute 'objectStore' on 'IDBTransaction': The transaction has finished." name: "InvalidStateError"

my code is simple: return await this.table.update(id, { examineDate: data.examineDate }) but,it return error notice like that ↑,I found so many answers from google and github and stackoverflow but no one useful help me please,it's very urgent, thx @dfahlander 🙏

jawalkwan avatar May 08 '22 08:05 jawalkwan

This happens when you execute a transaction and await non-Dexie calls within it.

await db.transaction('rw', db.myTable, async () => {
  await fetch('https://xyz.org/...'); // Here's a problem: awaiting non-dexie call within a transaction
  return await this.table.update(id, { examineDate: data.examineDate });
});

This is also described here

If your function is not executing within a transaction, the case can also be that your caller has the transaction block and calls your function within it after doing the non-dexie work.

Let me know if that was the case and what version of dexie you are using.

dfahlander avatar May 08 '22 13:05 dfahlander

alright, I installed latest version dexie in my project my code in function just has one line ,like this:

async update(data: any) {
return await this.table.update(id, { examineDate: data.examineDate })
}

haven't transaction around of them. I ever tried to write the transaction around of this codes, but didn't work

jawalkwan avatar May 08 '22 14:05 jawalkwan

Are you using a very old browser or Internet Explorer, Legacy Edge or very old version of some other browser?

dfahlander avatar May 09 '22 07:05 dfahlander

These type of problems occur on very old browsers - but also when using IndexedDBShim or possibly also fakeIndexedDB instead of using the native IndexedDB in the browser.

One workaround is to transpile the application code to <= ES2016 to get rid of the ES2017 async/await keywords which in those environments are incompatible with IndexedDB transactions.

dfahlander avatar May 09 '22 07:05 dfahlander

I using the latest version electron, it included chromium version about 100.x, so I don't think about it's reason for browser's version. My frontend platform using vue3+vite,it would translate the typescript code to es2015 and support async/await better, I also not doubt the trouble is from code's version maybe i was wrong, if you need, I can make and share a demo with the problem to you for position the problem

jawalkwan avatar May 09 '22 07:05 jawalkwan

btw, did you have obstacle for my english? my grammar was too terrible😂

jawalkwan avatar May 09 '22 07:05 jawalkwan

Check if IndexedDBShim is included. Try remove it. If you'd still need IndexedDBShim, make sure to transpile the code to ES2016 or ES2015.

No problem with your English :)

dfahlander avatar May 09 '22 07:05 dfahlander

Ok, I will try it later and give the feedback to you when it still don't work Thank you so much!😉

jawalkwan avatar May 09 '22 08:05 jawalkwan

I had a similar problem, Sentry sounds the alarm: "InvalidStateError: Failed to execute 'abort' on 'IDBTransaction': The transaction has finished."

my environment: Electron Version:13.1.7. my Dexie.js version: 3.0.1.

help me please,it's very urgent, thx @dfahlander

licao404 avatar May 18 '22 13:05 licao404

@licao404 我按大佬的方法试了还是没啥用,现在已经转sqlite了,因为项目比较急,没时间研究,所以兄弟你要不要也先用sqlite试试,这个库好像在electron下有点纠结😂

jawalkwan avatar May 18 '22 13:05 jawalkwan

@delayhsiao 好像也不是这个库独有的问题,这个库你用的是哪个版本,我看其他indexdb库下也有类似的issues,评论基本上说是浏览器内核的bug。难搞啊

licao404 avatar May 18 '22 13:05 licao404

@delayhsiao 好像也不是这个库独有的问题,这个库你用的是哪个版本,我看其他indexdb库下也有类似的issues,评论基本上说是浏览器内核的bug。难搞啊

我用的最新版,反正大家都在吹indexeddb,但是我发现这玩意儿就跟h5早期状态一样,各家都有不同的支持状态。所以我现在转了sqlite3,用得很流畅,性能什么的,反正单机给个loading让它转就完事儿了

jawalkwan avatar May 18 '22 14:05 jawalkwan

I had a similar problem, Sentry sounds the alarm: "InvalidStateError: Failed to execute 'abort' on 'IDBTransaction': The transaction has finished."

my environment: Electron Version:13.1.7. my Dexie.js version: 3.0.1.

help me please,it's very urgent, thx @dfahlander

I don't know if it's similar to these issues :

  • https://github.com/jakearchibald/idb/issues/229
  • https://github.com/dexie/Dexie.js/issues/613

@dfahlander

licao404 avatar May 18 '22 14:05 licao404

Can you confirm whether IndexedDBShim is being used or not? If IndexedDBShim is used, you must either avoid using async/await or transpile your code to ES2016 (or ES2015 or ES5) in order to avoid native async/await as it will not work with IndexedDBShim.

In order to use Dexie in node (Electron main process is a node process), IndexedDBShim can be used as an adapter between the IndexedDB API and SQLite, but IndexedDBShim has the same issues as browsers used to have historically - it won't keep transactions alive between micro ticks.

dfahlander avatar May 18 '22 14:05 dfahlander

same problem and no solution 😢

ArcherGu avatar May 15 '23 08:05 ArcherGu

Using the put method and abandoning the update method can solve the problem. Currently I am using this solution

superocky avatar Sep 14 '23 01:09 superocky

@superocky & @ArcherGu Are you in a browser platform, Electron or is this happening in node based unit tests (using IndexedDBShim or fakeIndexedDB to run tests in node)? What's your user agent & version? It would also help if someone could create a repro of this problem or else pin point the platforms where this happens.

dfahlander avatar Sep 14 '23 13:09 dfahlander

some problem

the-didi avatar Nov 24 '23 09:11 the-didi