Fix ADDRESS field persist error when lat/lng values are strings

The addressLat and addressLng fields use the NUMERIC type (BigFloat scalar),
which can arrive as strings in some data paths. The Zod validation schema
in isFieldAddressValue only accepted numbers, causing the persist operation
to throw "Invalid value to persist" for ADDRESS type fields.

Updated the schema and types to accept both string and number values for
addressLat and addressLng.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Sonarly Claude Code
2026-02-18 22:49:42 +00:00
co-authored by Claude Opus 4.6
parent 66deb8be63
commit d6c53b40bb
4 changed files with 21 additions and 6 deletions
@@ -55,8 +55,8 @@ export type FieldAddressDraftValue = {
addressState: string | null;
addressPostcode: string | null;
addressCountry: string | null;
addressLat: number | null;
addressLng: number | null;
addressLat: number | string | null;
addressLng: number | string | null;
};
export type FieldJsonDraftValue = string;
export type FieldActorDraftValue = {
@@ -267,8 +267,8 @@ export type FieldAddressValue = {
addressState: string | null;
addressPostcode: string | null;
addressCountry: string | null;
addressLat: number | null;
addressLng: number | null;
addressLat: number | string | null;
addressLng: number | string | null;
};
export type FieldSelectValue = string | null;
export type FieldMultiSelectValue = string[] | null;
@@ -34,6 +34,21 @@ describe('isFieldAddressValue', () => {
).toBe(true);
});
it('should return true for address values with string lat/lng', () => {
expect(
isFieldAddressValue({
addressStreet1: '',
addressStreet2: '',
addressCity: '',
addressState: '',
addressPostcode: '',
addressCountry: 'Türkiye',
addressLat: '38.963745',
addressLng: '35.243322',
}),
).toBe(true);
});
it('should return false for incomplete address', () => {
expect(isFieldAddressValue({ addressStreet1: '123 Main St' })).toBe(false);
});
@@ -10,8 +10,8 @@ export const addressSchema = z.object({
addressState: z.string().nullable(),
addressPostcode: z.string().nullable(),
addressCountry: z.string().nullable(),
addressLat: z.number().nullable(),
addressLng: z.number().nullable(),
addressLat: z.union([z.number(), z.string()]).nullable(),
addressLng: z.union([z.number(), z.string()]).nullable(),
});
export const isFieldAddressValue = (