Merge pull request #13246 from Budibase/fix/deleting-attachment-column-with-empty-values

Fix - Allow deleting attachment column with empty values
This commit is contained in:
Adria Navarro 2024-03-13 18:45:36 +01:00 committed by GitHub
commit 563eada394
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View File

@ -43,7 +43,7 @@ export class AttachmentCleanup {
if ((columnRemoved && !renaming) || opts.deleting) {
rows.forEach(row => {
files = files.concat(
row[key].map((attachment: any) => attachment.key)
(row[key] || []).map((attachment: any) => attachment.key)
)
})
}

View File

@ -115,4 +115,31 @@ describe("attachment cleanup", () => {
await AttachmentCleanup.rowUpdate(table(), { row: row(), oldRow: row() })
expect(mockedDeleteFiles).not.toBeCalled()
})
it("should be able to cleanup a column and not throw when attachments are undefined", async () => {
const originalTable = table()
delete originalTable.schema["attach"]
await AttachmentCleanup.tableUpdate(
originalTable,
[row("file 1"), { attach: undefined }, row("file 2")],
{
oldTable: table(),
}
)
expect(mockedDeleteFiles).toBeCalledTimes(1)
expect(mockedDeleteFiles).toBeCalledWith(BUCKET, ["file 1", "file 2"])
})
it("should be able to cleanup a column and not throw when ALL attachments are undefined", async () => {
const originalTable = table()
delete originalTable.schema["attach"]
await AttachmentCleanup.tableUpdate(
originalTable,
[{}, { attach: undefined }],
{
oldTable: table(),
}
)
expect(mockedDeleteFiles).not.toBeCalled()
})
})