"Error: Write outside of transaction" with convex-test
I'm a bit lost how i go about debugging/fixing an error only thrown inside a test. The code works fine when running against real backend, but when running through vitest with convex-test backedn I get this error: "Error: Write outside of transaction 10126;feed". There is nothing special about the code, it just does a pretty normal
db.insert(...)
. Any ideas how to tackle this?6 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
hmm this is a new assertion so there might be issues with it. can you share your test code? two things to watch out for:
1. make sure you're awaiting all promises.
2. if you're using the scheduler, make sure everything scheduled by a test finishes before the test completes.
The code is nested a bit, this is the part resulting in the error:
probably not very helpful on its own 🙂
I'm not using scheduler, but now I'm checking if all promises are awaited...
Because the actual tests are all successful, just in the end the error comes up. (But I'm not verifying that the feed entry is created in the test as this is rather a sideeffect / not focus of the testcase.)
Yes, somewhere up the call chain an await was missing 🙂
ooh cool
Thank you for the quick response @lee
i'm trying to think of whether the test can detect this and print a better error 🤔