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

未关闭
#4,302 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
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 能够在 embedded 模式下正常工作且不再出现 parameter-not-provided 错误时,即完成。

由索引模型根据 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

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

electric-sql/electric 的其他 Issue

查看 electric-sql/electric 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。