fix(schema): accept null dateReceived and nullish generic occurrence - #1238
Conversation
There was a problem hiding this comment.
The schema changes match upstream Sentry: BaseEventSerializerResponse declares both dateReceived and occurrence nullable, and EventSerializer.serialize() emits None for each when absent. The focused Vitest test passes, but the new assertion result.occurrence makes the repository's required pnpm run tsc fail with TS2339 because EventSchema.parse() returns a union that includes variants without that property. Please rewrite the assertion so it narrows/checks the property first (or otherwise remains valid against the union), then confirm the root typecheck passes.
|
will have junior clean up the remainder, thanks! |
Keep the null occurrence regression assertion compatible with the inferred EventSchema union. Co-authored-by: OpenAI Codex <noreply@openai.com> Co-Authored-By: David Cramer <david@sentry.io>
Addressed in commit 73a76be; root typecheck now passes.
|
Addressed the review feedback in |
Summary
Accept nullable date fields in
EventSchemaresponses that are valid according to the Sentry API contract.Problem
On a self-hosted Sentry instance, the event API returned this payload:
{"id":"2d9a3f30ee5a4a95b712e78b87631f9a","eventID":"2d9a3f30ee5a4a95b712e78b87631f9a","type":"default","dateReceived":null,"occurrence":null}EventSchema.parsethen raised aninvalid_unionZod error. In particular, thedateReceivedbranch expected a string but receivednull. This preventsget_sentry_resourcefrom returning issue and breadcrumbs resources for affected events.API contract evidence
This is a valid server response, not a server bug. The Sentry event serializer declares
dateReceivedasdatetime | None; whenreceivedis absent or invalid, the serializer can returnnull:getsentry/sentryevent serializer, lines 155-176getsentry/sentryevent serializer, lines 328-368Related precedent
firstSeenandlastSeenAPI dates acceptnullwithz.string().datetime().nullable().occurrence: nullfor transaction events after anEventSchemaZod error.null.nullish()for API fields whereoptional()rejects explicitnull.Change
dateReceivedtoz.string().datetime().nullish(). This follows the nullable-date intent of fix(api-client): allow null firstSeen/lastSeen on IssueSchema #910 while also retaining support for omitted fields.occurrencetoOccurrenceSchema.nullish(), consistent with thenullish()approach proposed in fix(mcp-core): Allow null for externalSlug/externalId in RepositorySchema #1236 and the transaction-event handling in fix(api-client): update event schema to match Sentry API responses #520.EventSchemaregression test fordateReceived: nulland genericoccurrence: null.Testing and regression coverage
The focused Vitest regression test was added but could not be run locally: Corepack was unable to download the repository-pinned
pnpm@11.8.0after 120-second and 300-second attempts, so dependencies could not be installed.git diff --checkpasses.CI should run the new test with:
pnpm --filter @sentry/mcp-core exec vitest run src/api-client/schema.test.ts