You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(Reported as a bug, as this used to be a feature supported in previous versions. I can't recall when this change happened)
Given a collection A and a o2m relationship with collection B through the field b_id, if you attempt to provide a value for b_id which has not yet been added to the collection B, you will receive a foreign key violation, which is to be expected.
However, I would like to recover from this position by creating a flow which either uses the request or a database error event. Unfortunately, the original payload (i.e. { "b_id": "something" }) isn't provided, thus making it hard to resolve the error by for instance creating the something ID inside the B collection.
To Reproduce
Create the two collections as described above. Create a flow which uses the request or database error event on collection A, and enable logging. Now try to append an entry to collection A by specifying an invalid b_id. Inside your log you will receive something like this:
{
"payload": {
"name": "DirectusError",
"message": "Invalid foreign key for field \"b_id\" in collection \"A\".",
"stack": "DirectusError: Invalid foreign key for field \"b_id\" in collection \"A\".\n at foreignKeyViolation (file:///directus/node_modules/.pnpm/file+api_@unhead+vue@1.8.9_pinia@2.1.7_typescript@5.3.3_vue@3.3.13/node_modules/@directus/api/dist/database/errors/dialects/postgres.js:87:12)\n at extractError (file:///directus/node_modules/.pnpm/file+api_@unhead+vue@1.8.9_pinia@2.1.7_typescript@5.3.3_vue@3.3.13/node_modules/@directus/api/dist/database/errors/dialects/postgres.js:21:20)\n at translateDatabaseError (file:///directus/node_modules/.pnpm/file+api_@unhead+vue@1.8.9_pinia@2.1.7_typescript@5.3.3_vue@3.3.13/node_modules/@directus/api/dist/database/errors/translate.js:26:28)\n at file:///directus/node_modules/.pnpm/file+api_@unhead+vue@1.8.9_pinia@2.1.7_typescript@5.3.3_vue@3.3.13/node_modules/@directus/api/dist/services/items.js:148:29\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"
},
"event": "database.error",
"client": "postgres"
}
Ideally, you would receive something like this:
{
"payload": {
"name": "DirectusError",
"message": "Invalid foreign key for field \"b_id\" in collection \"A\".",
"stack": "...",
"data": {
"b_id": "something"
}
"event": "database.error",
"client": "postgres"
}
Directus Version
v10.8.3
Hosting Strategy
Self-Hosted (Docker Image)
The text was updated successfully, but these errors were encountered:
Reported as a bug, as this used to be a feature supported in previous versions. I can't recall when this change happened
Looking through the code this was not a feature in Directus (9+) as version 9 was a complete rewrite we don't guarantee it to be feature complete with previous versions. Closing this issue for now as not a bug but feel free to create a feature request to get your wishes implemented.
I've found the code that was responsible for this feature. It is seems to be removed after v10.3 during the introduction of the new error handling package. The old error handler included a field called invalid which provided this information:
Ah i see where the misunderstanding happened, the complete "original payload" was never in the error but we did have a field for the specific value that was failing indeed.
Describe the Bug
(Reported as a bug, as this used to be a feature supported in previous versions. I can't recall when this change happened)
Given a collection
A
and ao2m
relationship with collectionB
through the fieldb_id
, if you attempt to provide a value forb_id
which has not yet been added to the collectionB
, you will receive a foreign key violation, which is to be expected.However, I would like to recover from this position by creating a flow which either uses the
request
or adatabase
error event. Unfortunately, the original payload (i.e.{ "b_id": "something" }
) isn't provided, thus making it hard to resolve the error by for instance creating thesomething
ID inside theB
collection.To Reproduce
Create the two collections as described above. Create a flow which uses the
request
ordatabase
error event on collectionA
, and enable logging. Now try to append an entry to collectionA
by specifying an invalidb_id
. Inside your log you will receive something like this:Ideally, you would receive something like this:
Directus Version
v10.8.3
Hosting Strategy
Self-Hosted (Docker Image)
The text was updated successfully, but these errors were encountered: