Skip to content

Postgres adapter reads break when the events table has columns the installed StoredEvent does not know about #130

Description

@wickedwukong

Summary

The Postgres adapter reads events with SELECT * and hands the rows straight to class_row(StoredEvent[...]). Any column in the events table that the installed version of StoredEvent does not know about becomes an unexpected keyword argument, and the read fails:

TypeError: StoredEvent.__init__() got an unexpected keyword argument 'metadata'

This makes purely additive schema changes breaking at read time, and it makes rolling deployments hard.

Why this matters

Adding metadata in 0.1.12a3 requires a migration on the events table. In a rolling deployment there is a window where the migrated table is live but old tasks still run 0.1.11. Those old tasks read the new column and crash, even though they never asked for it.

We worked around this in an expand/contract sequence of four PRs:

  1. Add a read shim to the 0.1.11 service so it tolerates the extra column (expand).
  2. Migrate the table with metadata JSONB NOT NULL DEFAULT 'null'::jsonb, no service change.
  3. Upgrade to 0.1.12a3 and delete the shim.
  4. Migrate again to drop the default, leaving metadata JSONB NOT NULL (contract).

Steps 1 and 3 exist only because of the SELECT * behaviour. Without them the upgrade would have been two migrations and one version bump.

Suggested fix

Either would remove the problem:

  • Select the columns the installed model has, instead of *. This is the stronger option: the query becomes self-describing and the adapter reads exactly what it can construct.
  • Ignore unknown columns when building the StoredEvent, so extra columns are dropped rather than passed to __init__.

Where

  • src/logicblocks/event/store/adapters/postgres/adapter.py:309 — select_clause = sql.SQL("SELECT *") in read_last_query
  • src/logicblocks/event/store/adapters/postgres/adapter.py — the four class_row(StoredEvent[str, JsonValue, JsonValue]) cursors (lines 747, 805, 894, 912)
  • src/logicblocks/event/persistence/postgres/query.py:109 — Star, used by the scan/query paths

Reproduce

  1. Run a service on 0.1.11.
  2. Add a metadata column to the events table.
  3. Read any event. The read raises the TypeError above.

Verified locally.

Activity

  1. added 2 commits that reference this issue on Oct 5, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions