PgQue icon indicating copy to clipboard operation
PgQue copied to clipboard

Clients: define behavior for SQL-valid NULL event type/payload

Open NikolayS opened this issue 7 months ago • 1 comments

Problem

Driver Message types assume type and/or payload are always non-null strings, but PgQue/PgQ low-level primitives can produce nullable ev_type / ev_data rows.

Examples:

  • Go: Message.Type string, Message.Payload string; scanning SQL NULL into these fields can fail.
  • TypeScript: Message.type: string, payload: string; raw row mapping assumes non-null.
  • Python type hints/docs similarly imply concrete values, though psycopg may return None.

SQL permits/directly supports lower-level producers such as insert_event(queue, null::text, null::text). Even if high-level send() normally supplies defaults/JSON, drivers expose raw received messages and should define behavior for SQL-valid events.

Why this matters

PgQue is explicitly a thin wrapper over PgQ primitives. Clients may consume queues populated by SQL or another language, not only by the same driver's high-level send().

Suggested fix

Decide one policy:

  1. Strict high-level API policy: document that drivers only support messages produced by PgQue high-level send() and reject/null-check others with clear typed errors.
  2. Robust PgQ-compatible policy: model nullable fields accurately:
    • Go: *string or pgtype.Text for Type/Payload
    • TypeScript: string | null
    • Python: Optional[str] / payload optional

Given PgQue's “thin wrapper over SQL primitives” stance, option 2 seems more honest.

Acceptance criteria

  • Tests cover receiving a SQL-inserted event with NULL type/payload, or docs explicitly declare this unsupported.
  • Type definitions match actual supported behavior.

NikolayS avatar Apr 30 '26 17:04 NikolayS

Shipped in v0.3.0-rc.2 (merged to main via #395 at f4c7457): https://github.com/NikolayS/PgQue/releases/tag/v0.3.0-rc.2

NikolayS avatar Nov 21 '26 16:11 NikolayS