Parametrized queries not working for `Electric.Client.poll/4` in embedded mode
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 58/100
Research direction
Start at Electric.Client.Embedded.request_to_params/1 and compare its handling with the HTTP path through Plug and Electric.Shapes.Api.validate/2. Run the embedded Electric.Client.poll/4 reproduction with positional where parameters; it is done when the same ShapeDefinition works in embedded mode without the parameter-not-provided error.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- TypeScript
- Stars
- 10.4k
- Forks
- 399
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from electric-sql/electric
-
camelToSnake and snakeCamelMapper() drop the underscore when a digit precedes a camelCase boundaryOpen
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
electric-sql/electric#4855 ·
-
ShapeStream does not notify subscribers when it gives up on a non-Error valuePossibly taken @Tyagiquamar claimed this 19 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
electric-sql/electric#4830 ·
-
@electric-sql/client throws SecurityError on import when the browser blocks site storage (typeof localStorage outside try)Possibly taken @mohanedmoh claimed this 37 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
electric-sql/electric#4826 · 1 comment ·
-
agents-chat-starter: spawn PUT goes to the durable-streams proxy, so no entity is created and agents never wakePossibly taken @adityavkk claimed this 133 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
electric-sql/electric#4687 ·
-
Listen IP addressOpenfeature request triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
electric-sql/electric#4150 · 1 comment ·
All issues in electric-sql/electric
Similar issues
-
area:cli area:security bug priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
"code source" and "numerique.gouv" links: "new window" mention duplicated in the accessible nameOpenaccessibility
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
numerique-gouv/lasuite-landingpage#315 ·
Maintainers usually reply within 1 day
-
needs:triage
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
HyeokjaeChoi/vaultme#585 ·
Maintainers usually reply within 1 day
-
enhancement priority/P2
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
beettlle/pi-smart-router#200 ·