source: snapshot key and table checks look tables up by name only, so a same-name table in another schema breaks the start

Aperta
#472 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go, postgresql
Ambito
databases

Direzione di ricerca

Start in source/snapshot/fetch_worker.go and trace validateKey and validateTable, then read the existing table lookup paths that use regclass and search_path. Add a regression test with same-name tables in two schemas and different key types, running it with search_path set to each schema. Done means both checks resolve the configured table consistently with the snapshot query.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

What happens

In the snapshot fetch worker (source/snapshot/fetch_worker.go, v0.21.0 and v0.21.1), two checks find a configured table by its bare name in the catalog. Neither uses a namespace or search_path:

  • validateKey reads the key column's type with
    SELECT a.atttypid::regtype FROM pg_class c JOIN pg_attribute a ON c.oid = a.attrelid WHERE c.relkind = 'r' AND a.attname = $1 AND c.relname = $2.
    When several schemas have a table with that name, it takes whichever row comes first.
  • validateTable checks SELECT EXISTS(SELECT tablename FROM pg_tables WHERE tablename=$1). That passes when any schema has the name.

Every other lookup resolves the configured name through the connection's search_path: the primary-key lookups ($1::regclass), the snapshot query, the OID lookup and the publication (FOR TABLE "<name>"). The checks can therefore inspect a different table from the one the source reads.

Reproduction

Postgres 16, tables: items, url with search_path=inventory:

CREATE SCHEMA inventory;
CREATE TABLE inventory.items (id bigint PRIMARY KEY);
CREATE TABLE public.items (id text PRIMARY KEY);
  • The source refuses to start with key "id" of type "text" is unsupported. It checked public.items, but the table it reads is inventory.items.
  • With the types swapped (inventory.items text, public.items bigint), validation passes. The snapshot then fails on COALESCE(max("id"), 0) with SQLSTATE 42804.

Both failures are loud, so no record is lost or misread. But a correctly configured pipeline cannot start, and the error names the wrong table's column type.

Why it matters now

The source supports only bare tables entries (schema-qualified names are #277). Reading a table outside public therefore means setting search_path in url. conduit migrate kafka-connect now does exactly that for a Debezium table.include.list in one schema (ConduitIO/conduit#3350). Any database that has the same table name in another schema hits this bug.

Fix

Resolve the table the same way as everywhere else. In validateKey, join on c.oid = $2::regclass with internal.WrapSQLIdent(table) instead of c.relname = $2. In validateTable, use to_regclass($1) IS NOT NULL with the wrapped identifier instead of searching pg_tables by name. Add a regression test with a same-name table in two schemas whose key columns have different types. Run it once with search_path pointing at each schema.

Lingua principale
Go
Stelle
20
Fork
12
Merge medio
9h 50m
PR unite (30g)
29

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ConduitIO/conduit-connector-postgres

Tutte le issue di ConduitIO/conduit-connector-postgres

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.