Parametrized queries not working for `Electric.Client.poll/4` in embedded mode

Aperta
#4,302 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
elixir
Ambito
api, backend

Direzione di ricerca

Inizia da Electric.Client.Embedded.request_to_params/1 e confronta la relativa gestione con il percorso HTTP tramite Plug e Electric.Shapes.Api.validate/2. Esegui la riproduzione di Electric.Client.poll/4 in modalità embedded con parametri where posizionali; è completata quando la stessa ShapeDefinition funziona in modalità embedded senza l’errore parameter-not-provided.

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

Descrizione

triage

Versions

  • Client: electric_client (Elixir) 0.10.1
  • Electric: 1.6.2 (also reproducible on main)

Bug description

A ShapeDefinition whose where: clause uses positional parameters ($1, $2, …) with params: substitution works over HTTP but fails under Electric.Client.embedded/1 with "At location N: parameter $1 was not provided":

{:ok, client} = Electric.Client.embedded()

shape =
  Electric.Client.ShapeDefinition.new!("things",
    where: "organization_id IN ($1::uuid, $2::uuid)",
    params: %{1 => uuid_a, 2 => uuid_b}
  )

Electric.Client.poll(client, shape, Electric.Client.ShapeState.new(offset: "now"))
# => {:error, %Electric.Client.Error{
#      message: %{errors: %{where: ["At location 20: parameter $1 was not provided"]}}, ...}}

Root cause: ShapeDefinition.params/2 defaults to format: :query and emits bracket-flat keys (%{"params[1]" => ..., "params[2]" => ...}) — correct for HTTP, where Plug's fetch_query_params re-nests them into %{"params" => %{"1" => ..., "2" => ...}} before Electric.Shapes.Api.Params's Ecto cast sees them. Electric.Client.Embedded.request_to_params/1 skips Plug and Map.merges the bracket-flat map straight into Api.validate/2; the Ecto schema has no field "params[1]", silently drops both keys, and the SQL parser then rejects $1.

Expected behavior

Electric.Client.Embedded should accept the same ShapeDefinition shape as Electric.Client.Fetch.HTTP does, including parameterized where: clauses. Fix is to re-nest one level of bracket keys in Embedded.request_to_params/1 before handing off to Api.validate/2 — equivalent to what Plug does for the HTTP path.

Lingua principale
TypeScript
Stelle
10.4k
Fork
399
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

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 electric-sql/electric

Tutte le issue di electric-sql/electric

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.