Browse Source

fix(core): Fix null reference error when hydrating entity

In the case that an entity has _only_ `localeString` or `localeText` custom fields, a
`Cannot convert undefined or null to object` error could result when hydrating the custom fields
because the entity itself did not have a customFields object.

Fixes #2264
Michael Bromley 2 years ago
parent
commit
5a2b2b78f5

+ 2 - 2
packages/core/src/service/helpers/locale-string-hydrator/locale-string-hydrator.ts

@@ -75,8 +75,8 @@ export class LocaleStringHydrator {
                 }
                 }
                 if (localeStringProp === 'customFields') {
                 if (localeStringProp === 'customFields') {
                     (entity as any)[localeStringProp] = Object.assign(
                     (entity as any)[localeStringProp] = Object.assign(
-                        (entity as any)[localeStringProp],
-                        (translated as any)[localeStringProp],
+                        (entity as any)[localeStringProp] ?? {},
+                        (translated as any)[localeStringProp] ?? {},
                     );
                     );
                 } else {
                 } else {
                     (entity as any)[localeStringProp] = (translated as any)[localeStringProp];
                     (entity as any)[localeStringProp] = (translated as any)[localeStringProp];