Skip to content

fix(pglogstore): events with no metadata fail to insert (jsonb NOT NULL) under pgx v5.10 #972

Description

@alexluong

Summary

Publishing an event without metadata fails to persist when Outpost uses the Postgres log store. The event insert is rejected by Postgres and the log worker retries forever:

insert events failed: ERROR: null value in column "metadata" of relation "events_default" violates not-null constraint (SQLSTATE 23502)

Events (and their attempts) never become queryable. ClickHouse log store is unaffected.

Root cause

events.metadata is jsonb NOT NULL (since migration 000001_init). In internal/logstore/pglogstore/pglogstore.go, eventArrays() binds e.Metadata directly into the $8::jsonb[] insert param:

metadatas[i] = e.Metadata   // nil when the event has no metadata

A published event with no metadata has Metadata == nil (a nil map[string]string). With pgx v5.10.0 a nil map element in a jsonb[] array encodes to SQL NULL, which violates the NOT NULL column → insert fails. The same applies to attemptArrays()attempts.event_metadata (also NOT NULL).

Why it regressed now

Reproduction

Run spec-sdk-tests against an Outpost configured with the Postgres log store (this is what the spec-sdk-tests CI workflow does). The 3 event/attempt tests in Events (PR #491) time out:

  • should list events by tenant
  • publishing an event ... should generate an attempt
  • listAttempts with include=event.data ...

Confirmed locally with LOCAL_DEV_POSTGRES=1 + postgres: log store in .outpost.yaml — identical failure and Postgres error.

Fix

Default nil metadata to an empty map before binding, in both eventArrays() and attemptArrays():

metadata := e.Metadata
if metadata == nil {
    metadata = map[string]string{}
}
metadatas[i] = metadata

Verified locally: with this change the suite goes back to 153 passing / 15 pending / 0 failing and the log worker logs no metadata errors.

Notes

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions