Fix creating new relation when applying snapshot diff (#18879)

* Fix creating new relation when applying snapshot diff (#18692)

* Update apply-diff.ts

Collection and field might not be part of the dif but are mandatory

* Update contributors.yml

* Update apply-diff.ts

* prettier

* Add changeset

---------

Co-authored-by: gkielwasser <gkielwasser@gmail.com>
This commit is contained in:
Rijk van Zanten
2023-06-13 10:51:58 -04:00
committed by GitHub
parent 57747f0c7e
commit 7f961d51ec
3 changed files with 14 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
'@directus/api': patch
---
Fixed a problem that could cause snapshot apply to fail when a relationship changed

View File

@@ -275,7 +275,14 @@ export async function applyDiff(
if (diff?.[0]?.kind === DiffKind.NEW) {
try {
await relationsService.createOne((diff[0] as DiffNew<Relation>).rhs, mutationOptions);
await relationsService.createOne(
{
...(diff[0] as DiffNew<Relation>).rhs,
collection,
field,
},
mutationOptions
);
} catch (err) {
logger.error(`Failed to create relation "${collection}.${field}"`);
throw err;

View File

@@ -37,6 +37,7 @@
- ChuckMoe
- groksrc
- timio23
- gkielwasser
- craigharman
- acautin
- ninogjoni