Repository navigation
Closed
Labels
status: needs-triagePossible bug which hasn't been reproduced yet
Description
Link to reproduction
Describe the Bug
When I try to save a new document payload crash with the following error:
[15:46:31] ERROR (payload): NotFound: The requested resource was not found.
at findByID (/Users/matteotortelli/progetti/evoluzione/evoluzione-backend/node_modules/payload/src/collections/operations/findByID.ts:114:15)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async findByIDHandler (/Users/matteotortelli/progetti/evoluzione/evoluzione-backend/node_modules/payload/src/collections/requestHandlers/findByID.ts:19:17)
[15:46:37] WARN (payload): rollbackTransaction called when no transaction exists
/Users/matteotortelli/progetti/evoluzione/evoluzione-backend/node_modules/mongodb/src/cmap/connection.ts:449
callback(new MongoServerError(document));
^
MongoServerError: Transaction with { txnNumber: 15 } has been committed.
at Connection.onMessage (/Users/matteotortelli/progetti/evoluzione/evoluzione-backend/node_modules/mongodb/src/cmap/connection.ts:449:20)
at MessageStream.<anonymous> (/Users/matteotortelli/progetti/evoluzione/evoluzione-backend/node_modules/mongodb/src/cmap/connection.ts:241:56)
at MessageStream.emit (node:events:513:28)
at MessageStream.emit (node:domain:489:12)
at processIncomingData (/Users/matteotortelli/progetti/evoluzione/evoluzione-backend/node_modules/mongodb/src/cmap/message_stream.ts:188:12)
at MessageStream._write (/Users/matteotortelli/progetti/evoluzione/evoluzione-backend/node_modules/mongodb/src/cmap/message_stream.ts:69:5)
at writeOrBuffer (node:internal/streams/writable:392:12)
at _write (node:internal/streams/writable:333:10)
at MessageStream.Writable.write (node:internal/streams/writable:337:10)
at TLSSocket.ondata (node:internal/streams/readable:766:22) {
ok: 0,
code: 256,
codeName: 'TransactionCommitted',
'$clusterTime': {
clusterTime: Timestamp { low: 3, high: 1699544797, unsigned: true },
signature: { hash: [Binary], keyId: [Long] }
},
operationTime: Timestamp { low: 2, high: 1699544797, unsigned: true },
[Symbol(errorLabels)]: Set(0) {}
}
[nodemon] app crashed - waiting for file changes before starting...Despite the error, in the database there is the document.
Instead if I add the revisions I found two revisions and one doc from this saving.
After the saving the UI tells me that the document doesn't exists.
The error occour with the database in digitalOcean instead it didn't happen in local (I created a new database to test it).
Before migrating to Payload 2 everything worked well.
If I remove the nestedDocs plugin, it work correctly.
To Reproduce
- Add the following config in payload.config.ts
export default buildConfig({
db: mongooseAdapter({
url: process.env.MONGODB_URI,
connectOptions: {},
}),
editor: lexicalEditor({}),
admin: {
bundler: webpackBundler(),
},
collections: [
{
slug: "posts",
fields: [
{
name: "title",
type: "text",
},
],
},
],
plugins: [
nestedDocs({
collections: ["posts"],
generateLabel: (docs, currentDoc) => {
if (typeof currentDoc.title === "string") return currentDoc.title;
},
generateURL: (docs, currentDoc) => {
return docs.reduce((url, doc) => `${url}/${doc.slug}`, "") + "/";
},
}),
],
});- Login in the admin interface
- Add a new document
- the UI tells you that the document doesn't exist
- the backend crash and nothing works
- restart the server
- If you enable revisions in the list you see two documents
- If you don't enable revisions in the list you see one document
- click on the document, edit it and save it
- the backend crash again
Payload Version
2.1.0
Adapters and Plugins
"@payloadcms/bundler-webpack": "1.0.5", "@payloadcms/db-mongodb": "1.0.7", "@payloadcms/plugin-nested-docs": "1.0.8", "@payloadcms/richtext-lexical": "0.1.16",
Metadata
Metadata
Assignees
Labels
status: needs-triagePossible bug which hasn't been reproduced yet
Activity
revnelson commentedon Nov 9, 2023
Had this same issue, so I extracted the code from the plugin into hooks for a Categories collection. It seems like the issue is where the
reqobject is passed to the LocalAPI calls. By changing this line from({ req: { payload, locale }, req, doc })to({ req, doc })and changing alllocaleandpayloadreferences toreq.localeandreq.payloadrespectively, as well as removing req from all payload LocalAPI calls (i.e.payload.findpayload.updateetc) it seems to be working fine.Using
reqtwice in the arguments such as({ req: { payload, locale }, req, doc })seems odd to me, so I'm not sure if that's an issue, or if it was req being passed to LocalAPI (and what the purpose for that is in this instance). I also found in testing my "fixes" that it will still crash if there is circular nesting (i.e. B has parent A, C has parent B, A has parent C). Can't remember if the plugin had a guard against that, but I'll probably need to build out some filtering rule to not let that happen.DanRibbens commentedon Nov 9, 2023
The purpose for passing
reqto the local API is that it will force Payload to use the same transaction if transactions are being used by the database adapter. Transactions make sure you aren't updating one document, getting an error without rolling back changes in the DB.Since 2.1.0 included some DB transaction changes, I'm guessing that must be related.
Thanks for reporting. I should have all the info I need to provide a fix.
matteo-naif commentedon Nov 13, 2023
The problem isn't resolved, I have the following error saving a new doc in an empty collection:
/Users/matteotortelli/progetti/evoluzione/evoluzione-backend/node_modules/mongodb/src/transactions.ts:168 throw new MongoRuntimeError( ^ MongoRuntimeError: Attempted illegal state transition from [TRANSACTION_COMMITTED] to [TRANSACTION_ABORTED] at Transaction.transition (/Users/matteotortelli/progetti/evoluzione/evoluzione-backend/node_modules/mongodb/src/transactions.ts:168:11) at commandHandler (/Users/matteotortelli/progetti/evoluzione/evoluzione-backend/node_modules/mongodb/src/sessions.ts:740:27) at /Users/matteotortelli/progetti/evoluzione/evoluzione-backend/node_modules/mongodb/src/sessions.ts:810:7 at /Users/matteotortelli/progetti/evoluzione/evoluzione-backend/node_modules/mongodb/src/utils.ts:462:14 at processTicksAndRejections (node:internal/process/task_queues:95:5) { [Symbol(errorLabels)]: Set(0) {} } [nodemon] app crashed - waiting for file changes before starting...BrianJM commentedon Feb 22, 2024
@matteo-naif Still seeing this in #4350.
TechSynthesis commentedon Feb 27, 2024
@BrianJM Did you find the solution ? I'm getting this sporadically as well
BrianJM commentedon Feb 28, 2024
@TechSynthesis Are you seeing this sporadically only with Nested Docs or also without?
#4350 fixed the errors I saw without Nested Docs. It looks to be in the next release. I have not been able to test with Nested Docs yet.
TechSynthesis commentedon Feb 28, 2024
@BrianJM I started experiencing this when I updated one of my clients projects from payload 1.5 to 2.x. Went thought the whole migration process. Not sure where it's coming from. I do have a few collections that are nestedDocs
DanRibbens commentedon Feb 28, 2024
Anything more you can share @TechSynthesis? Ideally a reproducable issue you can document, but I can even debug from your project if you want to add me privately.
Also, what version of @payloadcs/plugin-nested-docs?
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.