Merge pull request #10483 from Budibase/fix/empty-attachment-row-import
Fix for row import failure caused by empty attachment parsing.
This commit is contained in:
commit
1c81cc4b4d
|
@ -212,6 +212,7 @@ describe("/rows", () => {
|
||||||
attachmentNull: attachment,
|
attachmentNull: attachment,
|
||||||
attachmentUndefined: attachment,
|
attachmentUndefined: attachment,
|
||||||
attachmentEmpty: attachment,
|
attachmentEmpty: attachment,
|
||||||
|
attachmentEmptyArrayStr: attachment
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -239,6 +240,7 @@ describe("/rows", () => {
|
||||||
attachmentNull: null,
|
attachmentNull: null,
|
||||||
attachmentUndefined: undefined,
|
attachmentUndefined: undefined,
|
||||||
attachmentEmpty: "",
|
attachmentEmpty: "",
|
||||||
|
attachmentEmptyArrayStr: "[]",
|
||||||
}
|
}
|
||||||
|
|
||||||
const id = (await config.createRow(row))._id
|
const id = (await config.createRow(row))._id
|
||||||
|
@ -268,6 +270,7 @@ describe("/rows", () => {
|
||||||
expect(saved.attachmentNull).toEqual([])
|
expect(saved.attachmentNull).toEqual([])
|
||||||
expect(saved.attachmentUndefined).toBe(undefined)
|
expect(saved.attachmentUndefined).toBe(undefined)
|
||||||
expect(saved.attachmentEmpty).toEqual([])
|
expect(saved.attachmentEmpty).toEqual([])
|
||||||
|
expect(saved.attachmentEmptyArrayStr).toEqual([])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import { FieldTypes } from "../../constants"
|
import { FieldTypes } from "../../constants"
|
||||||
|
import { logging } from "@budibase/backend-core"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A map of how we convert various properties in rows to each other based on the row type.
|
* A map of how we convert various properties in rows to each other based on the row type.
|
||||||
|
@ -67,9 +68,23 @@ export const TYPE_TRANSFORM_MAP: any = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[FieldTypes.ATTACHMENT]: {
|
[FieldTypes.ATTACHMENT]: {
|
||||||
"": [],
|
|
||||||
[null]: [],
|
[null]: [],
|
||||||
[undefined]: undefined,
|
[undefined]: undefined,
|
||||||
|
parse: attachments => {
|
||||||
|
if (typeof attachments === "string") {
|
||||||
|
if (attachments === "") {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
let result
|
||||||
|
try {
|
||||||
|
result = JSON.parse(attachments)
|
||||||
|
} catch (e) {
|
||||||
|
logging.logAlert("Could not parse attachments", e)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
return attachments
|
||||||
|
},
|
||||||
},
|
},
|
||||||
[FieldTypes.BOOLEAN]: {
|
[FieldTypes.BOOLEAN]: {
|
||||||
"": null,
|
"": null,
|
||||||
|
|
Loading…
Reference in New Issue