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

オープン
#4,302 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
58/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
elixir
領域
api, backend

調査の方向性

Electric.Client.Embedded.request_to_params/1 から始め、その処理を Plug と Electric.Shapes.Api.validate/2 を経由する HTTP パスと比較します。positional where パラメータを使って embedded の Electric.Client.poll/4 の再現を実行します。同じ ShapeDefinition が parameter-not-provided エラーなしで embedded モードで動作すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
10.4k
フォーク
399
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

electric-sql/electric のほかの issue

electric-sql/electric の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。