diff --git a/.changeset/nine-masks-explode.md b/.changeset/nine-masks-explode.md new file mode 100644 index 0000000000..f6d1e27e75 --- /dev/null +++ b/.changeset/nine-masks-explode.md @@ -0,0 +1,5 @@ +--- +"@directus/api": patch +--- + +Added extra type check in apply-diff diff --git a/api/src/utils/apply-diff.ts b/api/src/utils/apply-diff.ts index 404d29ba3c..f448300461 100644 --- a/api/src/utils/apply-diff.ts +++ b/api/src/utils/apply-diff.ts @@ -181,9 +181,11 @@ export async function applyDiff( // delete top level collections (no group) first, then continue with nested collections recursively await deleteCollections( - snapshotDiff.collections.filter( - ({ diff }) => diff[0]?.kind === DiffKind.DELETE && (diff[0] as DiffDeleted).lhs.meta?.group === null - ) + snapshotDiff.collections.filter(({ diff }) => { + if (diff.length === 0 || diff[0] === undefined) return false; + const collectionDiff = diff[0] as DiffDeleted; + return collectionDiff.kind === DiffKind.DELETE && collectionDiff.lhs?.meta?.group === null; + }) ); for (const { collection, diff } of snapshotDiff.collections) {