Skip to content

Invalid JSON for schema-qualified type names requiring identifier quoting #296

Description

@AurelienVernay

Database version : Postgres 17.6
Plugin version : 2.6-2+b1
Using postgraphile V4 with "@graphile/subscriptions-lds" plugin at version "4.14.1".

Suppose we are working on a schema called "int". We define the following type & table :

CREATE TYPE int.int_pi_document_type AS ENUM(
    'DI',
    'PI',
    'OWNER'
);
CREATE TABLE int.int_pi_documents(
    id serial PRIMARY KEY,
    pi_id int,
    parent_id int,
    pi_document_type "int".int_pi_document_type,
    name text,
    relative_path text,
    mime_type text,
    size int,
    s3_bucket_name text,
    s3_object_name text,
    uploaded_by_user_id int,
    uploaded_at timestamptz
);

When executing a request that inserts rows into int.int_pi_directories, my postgraphile plugin will catch it & executes this request :

SELECT lsn, data FROM pg_catalog.pg_logical_slot_get_changes($1, $2, $3, 'add-tables', $4::text)

that request will produce an array of changes (inserts / updates) with a consistent quoting error on columntypes property :

"{\"change\":[{\"kind\":\"update\",\"schema\":\"int\",\"table\":\"int_pi_documents\",\"columnnames\":[\"id\",\"pi_id\",\"parent_id\",\"pi_document_type\",\"name\",\"relative_path\",\"mime_type\",\"size\",\"s3_bucket_name\",\"s3_object_name\",\"uploaded_by_user_id\",\"uploaded_at\"],\"columntypes\":[\"integer\",\"integer\",\"integer\",\"int\".int_pi_document_type,\"text\",\"text\",\"text\",\"integer\",\"text\",\"text\",\"integer\",\"timestamp with time zone\"],\"columnvalues\":[563,1848,682,\"PI\",\"file.pdf\",\"output/file.pdf\",\"application/pdf\",85703,\"test\",\"data\",43,\"2026-08-06 11:22:08.347596+00\"],\"oldkeys\":{\"keynames\":[\"id\"],\"keytypes\":[\"integer\"],\"keyvalues\":[563]}}]}"

(prettified):

{
  "change": [
    {
      "kind": "update",
      "schema": "int",
      "table": "int_pi_documents",
      "columnnames": [
        "id",
        "pi_id",
        "parent_id",
        "pi_document_type",
        "name",
        "relative_path",
        "mime_type",
        "size",
        "s3_bucket_name",
        "s3_object_name",
        "uploaded_by_user_id",
        "uploaded_at"
      ],
      "columntypes": [
        "integer",
        "integer",
        "integer",
        "int".int_pi_document_type, // here lies the problem
        "text",
        "text",
        "text",
        "integer",
        "text",
        "text",
        "integer",
        "timestamp with time zone"
      ],
      "columnvalues": [
        563,
        1848,
        682,
        "PI",
        "file.pdf",
        "output/file.pdf",
        "application/pdf",
        85703,
        "test",
        "data",
        43,
        "2026-08-06 11:22:08.347596+00"
      ],
      "oldkeys": {
        "keynames": ["id"],
        "keytypes": ["integer"],
        "keyvalues": [563]
      }
    }
  ]
}

That formatting issue causes my plugin to crash when trying to parse the output into an object using JSON.parse.
https://github.com/graphile/graphile-engine/blob/v4/packages/lds/src/pg-logical-decoding.ts#L180 & https://github.com/graphile/graphile-engine/blob/v4/packages/lds/src/pg-logical-decoding.ts#L79

My analysis of the postgres-wal2json plugin code led me to believe error is near this section :
https://github.com/eulerto/wal2json/blob/master/wal2json.c#L1235

But i'm not confident enough to propose a pull request of bugfix on my own (very little C experience).

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions