Repository navigation
Description
Link to reproduction
Describe the Bug
I was only able to reproduce this problem when using MongoDB Atlas. I cannot reproduce in my local development environment (Community Edition)
This bug affects the @payloadcms/plugin-nested-docs plugin.
When editing a parent relationship (either add or remove), and after the operation was successful, when I navigate to a collection list sometimes I get this MongoDB runtime error.
<path/to/project>/node_modules/mongodb/src/transactions.ts:168
throw new MongoRuntimeError(
^
MongoRuntimeError: Attempted illegal state transition from [TRANSACTION_COMMITTED] to [TRANSACTION_ABORTED]
at Transaction.transition (<path/to/project>/node_modules/mongodb/src/transactions.ts:168:11)
at commandHandler (<path/to/project>/node_modules/mongodb/src/sessions.ts:740:27)
at <path/to/project>/node_modules/mongodb/src/sessions.ts:810:7
at <path/to/project>/node_modules/mongodb/src/utils.ts:462:14
at processTicksAndRejections (node:internal/process/task_queues:95:5)
It does not always happen, sometimes I have to edit the parent a couple of times before the error is thrown. It also does not matter what collection I navigate to afterwards, but it only happens in collection views. That is, if I navigate to the admin home page, no errors until I try requesting a collection list.
For some reason I cannot reproduce this issue using a local database, only the Atlas instance. Both my local and cloud instances have the same collections setup, hooks, etc. There are some data differences, but that's it. In the repro I have a simplified setup with only the nested collection. I still need to test this simplified setup in Atlas.
Any idea what could be happening here?
To Reproduce
Follow the instruction on the repro.
- Install dependencies.
- Create parent and child documents.
- Navigate to any collection view to get the list of documents.
- Stuck in loading skeleton?
[YES] Check console errors.
[NO] Edit the child location by adding or removing the parent until navigating to the collection view crashes.
Payload Version
2.1.0
Adapters and Plugins
"@azure/storage-blob": "^12.16.0", "@payloadcms/bundler-webpack": "1.0.5", "@payloadcms/db-mongodb": "1.0.7", "@payloadcms/plugin-cloud": "2.2.6", "@payloadcms/plugin-cloud-storage": "1.1.1", "@payloadcms/plugin-form-builder": "^1.0.15", "@payloadcms/plugin-nested-docs": "^1.0.8", "@payloadcms/richtext-lexical": "0.1.16", "payload-plugin-resolve-alias": "^0.1.0"
Activity
[-]Attempted Illegal State Transition (MongoDB Atlas)[/-][+]Attempted illegal state transition (MongoDB Atlas)[/+]davelsio commentedon Nov 9, 2023
I noticed this code in
plugin-nested-docs/src/index.tsJudging by the docs and what the other hooks in the plugin do, could it be caused because it does not
awaitthepopulateBreadcrumbsfunction?[-]Attempted illegal state transition (MongoDB Atlas)[/-][+]Attempted illegal state transition (Nested-Docs + MongoDB Atlas)[/+]matteo-naif commentedon Nov 14, 2023
I have the same problem, any updates?
georgeharito commentedon Nov 14, 2023
Same problem here too, however for me it occurs whenever I save any collections that use the nested-docs plugin, and not just when I go to view the list of records in a nested-docs-enabled collection.
Keyideas-Rohan-Tiwari commentedon Nov 17, 2023
Same problem with me any update? When I'm running with local mongoDb connection its working fine, But when connecting with Atlas i'm getting this error.
hassanthegooner commentedon Nov 18, 2023
Getting the same issue using MongoDb Atlas but indeed, the seed works when using a local mongoDB instance
jon8800 commentedon Nov 19, 2023
Same issue here. This is related: #4077. @DanRibbens looks like it wasn't resolved with the recent update.
DanRibbens commentedon Nov 20, 2023
I tried very hard to reproduce this issue. Since I cannot I am going to commit the suggested fix from @Davelsan
#4072 (comment). It probably should be awaiting that anyways.
Another thing I considered is that the connection options being used in your mongodb connection string might have something to do with the variance in results. I haven't confirmed this, but I will share it anyways in case somebody else has experienced this or wants to try. I used a combination of
retryWrites=trueandw=majoritywhen testing, perhaps there are other settings that are the cause.davelsio commentedon Dec 3, 2023
Hey @DanRibbens, thanks for adding the fix. I have finally been able to update
payloadto2.3.1. I haven't been able to reproduce the issue after the update, so that looks good so far. I can't say for sure if the fix was my suggestion or what you did on2.1.1, but either way it seems fixed.I found another interesting (maybe-)bug with the plugin. I probably should report that separately, but just a comment in case someone else is running into this. It seems that using the
createParentFieldfactory function can produce the following error when trying to update theparentfield.I assume this must be a problem with
access.readin the field config. Anyway, I'll provide more details and a repro when I get around to creating the issue. For now, not using the function is good enough for me.Thanks again for your efforts! ❤️
bsides commentedon Dec 6, 2023
Hi guys, I'm getting the same error with payload-demo. I didn't do anything, just ran the project, after a while, it threw this message. Now every time I try to run the app via
pnpm devI get the same message. I'm using a new mongodb atlas and fresh install. My connection string is the one given by mongodb atlas, which is something like this:mongodb+srv://MY_USERNAME:MY_PASSWORD@cluster-CLUSTER_NAME.SOME_STRING.mongodb.net/github-actions commentedon Sep 7, 2024
This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.