Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readwrite transaction in liveQuery context #1831

Closed
dfahlander opened this issue Nov 27, 2023 · 4 comments
Closed

Readwrite transaction in liveQuery context #1831

dfahlander opened this issue Nov 27, 2023 · 4 comments

Comments

@dfahlander
Copy link
Collaborator

The error ReadOnly Error: "Readwrite transaction in liveQuery context" can happen in dexie v4.0.1-beta.1, v4.0.1-alpha.25, v4.0.1-alpha.24 and v4.0.1-alpha.23 even when the querier did not perform any 'rw' transaction at all if the observer of the liveQuery performs a 'rw' transaction in the next micro task after it has been triggered. The issue was reported on a nextjs application using dexie@4.x and was a result of react scheduling an useEffect that did an 'rw' transaction.

dfahlander added a commit that referenced this issue Nov 27, 2023
@frankleng
Copy link

@dfahlander still getting this consistently

Error\n    at getErrorWithStack (webpack-internal:///../../node_modules/.pnpm/dexie@4.0.1-beta.4/node_modules/dexie/dist/modern/dexie.mjs:317:12)\n    at new DexieError (webpack-internal:///../../node_modules/.pnpm/dexie@4.0.1-beta.4/node_modules/dexie/dist/modern/dexie.mjs:416:19)\n    at Object.transaction (webpack-internal:///../../node_modules/.pnpm/dexie@4.0.1-beta.4/node_modules/dexie/dist/modern/dexie.mjs:4489:27)\n    at Transaction.create (webpack-internal:///../../node_modules/.pnpm/dexie@4.0.1-beta.4/node_modules/dexie/dist/modern/dexie.mjs:2680:32)\n    at eval (webpack-internal:///../../node_modules/.pnpm/dexie@4.0.1-beta.4/node_modules/dexie/dist/modern/dexie.mjs:4040:23)\n    at eval (webpack-internal:///../../node_modules/.pnpm/dexie@4.0.1-beta.4/node_modules/dexie/dist/modern/dexie.mjs:1167:23)\n    at callListener (webpack-internal:///../../node_modules/.pnpm/dexie@4.0.1-beta.4/node_modules/dexie/dist/modern/dexie.mjs:890:19)\n    at endMicroTickScope (webpack-internal:///../../node_modules/.pnpm/dexie@4.0.1-beta.4/node_modules/dexie/dist/modern/dexie.mjs:964:25)\n    at eval (webpack-internal:///../../node_modules/.pnpm/dexie@4.0.1-beta.4/node_modules/dexie/dist/modern/dexie.mjs:946:34)\n    at usePSD (webpack-internal:///../../node_modules/.pnpm/dexie@4.0.1-beta.4/node_modules/dexie/dist/modern/dexie.mjs:1154:16)\n    at physicalTick (webpack-internal:///../../node_modules/.pnpm/dexie@4.0.1-beta.4/node_modules/dexie/dist/modern/dexie.mjs:945:5)"

ReadOnlyError: Readwrite transaction in liveQuery context. Querier source: async ()=>{
     //.....
    }

@dfahlander
Copy link
Collaborator Author

You're right. I've found the reason and will release a new version today.

@frankleng
Copy link

reverted back to 3.2.4 for now.
thank u for the hardwork!

@dfahlander
Copy link
Collaborator Author

@franleng thanks! The new release 4.0.1-beta.5 should probably be a better as long as the querier only performs pure read queries only and does not have any side effects (like setting state of another component, mutating DOM etc). The same principle goes for 3.2.4, but the difference is that it will not complain when it happens.

Let me know if you'd have a chance to try 4.0.1-beta.5 just to verify the problem goes away. If not, check whether your callback to liveQuery() may have side effects or write to the DB. If still any issue, I'd be happy to troubleshoot it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants