Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 'oldValue' must be a string error when viewing version diffs in postgres #10313

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ const generateLabelFromValue = (
}

let relatedDoc: RelationshipValue
let valueToReturn = '' as any
let valueToReturn: RelationshipValue | string = ''

const relationTo = 'relationTo' in field ? field.relationTo : undefined

if (value === null || typeof value === 'undefined') {
// eslint-disable-next-line @typescript-eslint/no-base-to-string -- We want to return a string specifilly for null and undefined
return String(value)
}

Expand Down Expand Up @@ -76,19 +77,22 @@ const generateLabelFromValue = (
valueToReturn = relatedDoc
}

if (typeof valueToReturn === 'object' && titleFieldIsLocalized) {
if (typeof valueToReturn === 'object' && titleFieldIsLocalized && valueToReturn?.[locale]) {
valueToReturn = valueToReturn[locale]
}
} else if (relatedDoc) {
// Handle non-polymorphic `hasMany` relationships or fallback
if (typeof relatedDoc?.id !== 'undefined') {
valueToReturn = relatedDoc.id
valueToReturn = String(relatedDoc.id)
} else {
valueToReturn = relatedDoc
}
}

if (typeof valueToReturn === 'object' && valueToReturn !== null) {
if (
(valueToReturn && typeof valueToReturn === 'object' && valueToReturn !== null) ||
typeof valueToReturn !== 'string'
) {
valueToReturn = JSON.stringify(valueToReturn)
}

Expand Down
Loading