Skip to content

fix(profile): zod 4.6 throws on .pick() over a refined schema — five employment cards stop saving, silently #910

Closed

Description

@thinkclay

Found while investigating why #870 (the backend Dependabot group) is red. zod 4.1.13 → 4.6.5 is the sole cause and the failure is a real behaviour change, not a test artifact.

Evidence that it is zod alone

On #870's branch, with every other bump in the group applied:

zod profile-employment-left.test.tsx
4.6.5 (the bump) 31 passed, 9 failed
4.1.13 (pinned back, nothing else changed) 40 passed, 0 failed

What changed

zod 4.6 added a guard that 4.1 did not have. Reduced to the two lines that matter:

const schema = z.object({ /* … */ }).partial().superRefine(/* … */)
schema.pick({ drivers_license_classes: true })
zod 4.1.13 -> works; returns { drivers_license_classes: ['Class A'] }
zod 4.6.5  -> Error: .pick() cannot be used on object schemas containing refinements

4.1 quietly allowed the pick and dropped the refinement. 4.6 refuses.

Why that is worse than a failing test

profileEmploymentInputSchema ends in .superRefine(...) (consolidated.ts:285-329), and five employment cards .pick() from it inside their save handler:

  • EmploymentDriversLicenseCard.tsx:41
  • EmploymentMilitaryCard.tsx:39
  • EmploymentAvailabilityCard.tsx:39
  • EmploymentLocationsCard.tsx:35
  • EmploymentHourlyRateCard.tsx:36

Each one is shaped like this:

const result = profileEmploymentInputSchema
  .pick({ drivers_license_classes: true })
  .safeParse({ drivers_license_classes: next })
if (!result.success) return          // <- silent

Under 4.6 the .pick() throws before safeParse is reached, on every interaction, inside an event handler. The user ticks a licence class and nothing is saved. And the existing if (!result.success) return means the non-throwing failure mode is equally silent — no toast, no log, no console warning. That is the whole Work Preferences / Work Qualifications form: hourly rate, work locations, driver's licence, military status, availability.

That is exactly what the test output shows — Number of calls: 0, or a save recorded for the boolean residency toggle and then nothing for the array field:

- ObjectContaining { "drivers_license_classes": ["Class A"] }
+ { "us_resident": true }

This is latent, not live. On main zod is 4.1.13, so the form works today. The bump is what would introduce it — which is the good news, and the reason #870 must not be merged as-is.

The fix

Keep the unrefined object addressable and attach the refinement after it, so callers that need one field pick from the base while routers keep validating against the refined schema. Verified against 4.6.5:

pick(base)         -> true {"drivers_license_classes":["Class A"]}
refine still fires -> true "Please select a travel distance"
valid full parse   -> true
  • Split consolidated.ts into profileEmploymentBaseSchema (the z.object({…}).partial()) and profileEmploymentInputSchema = profileEmploymentBaseSchema.superRefine(…), exporting both.
  • Point the five cards' .pick() at the base schema.
  • Give the if (!result.success) return branches a logger.warn at minimum — a validation failure that discards a user's input must not be silent. This is the part that turned a library guard into an invisible data-loss bug.
  • A test asserting .pick() on whatever the cards import does not throw, so the next refinement added to that schema fails loudly in CI instead of in the browser.

Checked and clear

The other two .pick() call sites are on plain z.object()s with no refinements and are unaffected: teamCreateBaseSchema (TeamForm.tsx:60) and adminCheckTypeSchema (background-checks.router.ts:193, background-checks-admin.ts:57).

Sequencing

#870 is also blocked by #907 (the Expo gate, fixed in #908). Once that clears, this still stands. Suggested order: land this fix, then let zod 4.6 in — either by re-running #870 or by splitting zod out so the posthog and tRPC bumps are not held behind it.

Activity

  1. added
    bug
    agent-ready
    on Sep 25, 2026
  2. thinkclay commented on Sep 25, 2026

    @thinkclay
    ContributorAuthor

    Fix is up in #912, with the acceptance list covered:

    • Schema split into profileEmploymentBaseSchema (the plain .partial() object) and profileEmploymentInputSchema (base + the travel rule). Routers keep the refined one.
    • The five cards pick from the base.
    • Every if (!result.success) return now logs the zod issues first.
    • employment-schema-pick.test.ts fails if a refinement is ever attached to the schema the cards import.

    Proved against the real version rather than reasoning about it — temporarily moved the catalog pin to 4.6.5, ran, then reverted:

    result
    zod 4.1.13, before 40 passed, 0 failed
    zod 4.6.5, before 31 passed, 9 failed
    zod 4.6.5, after 49 passed, 0 failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Frontendagent-readybug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions