Skip to content

fix(sync-service): allow DELETE /v1/shape to resolve a shape by its definition - #4754

Merged
alco merged 7 commits into
electric-sql:mainfrom
aayush-k:fix/delete-shape-by-definition
Aug 12, 2026
Merged

alco merged 7 commits into
electric-sql:mainfrom
aayush-k:fix/delete-shape-by-definition

Conversation

@aayush-k

@aayush-k aayush-k commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

DeleteShapePlug narrowed the incoming params to ["table", "handle"] before handing them to Api.validate_for_delete/2, dropping where/columns/params/ replica/log. The shape passed to Shapes.fetch_handle_by_shape/2 was therefore always the bare-table shape, so any shape defined with a where clause or a column selection could only ever be deleted by handle.

Widen the take list to every param that Api.Params.define_shape/2 reads and add plug- and router-level regression tests; the existing api_test.exs coverage calls validate_for_delete/2 directly and so bypasses the plug.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

aayush-k and others added 7 commits August 9, 2026 22:03
…efinition

DeleteShapePlug narrowed the incoming params to ["table", "handle"] before
handing them to Api.validate_for_delete/2, dropping where/columns/params/
replica/log. The shape passed to Shapes.fetch_handle_by_shape/2 was therefore
always the bare-table shape, so any shape defined with a where clause or a
column selection could only ever be deleted by handle.

Widen the take list to every param that Api.Params.define_shape/2 reads and
add plug- and router-level regression tests; the existing api_test.exs
coverage calls validate_for_delete/2 directly and so bypasses the plug.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
doesn't seem like this is used anymore
Removed the @shape_definition_params constant and updated the parameter handling in validate_request.
…tions

Build query strings with URI.encode_query/1 (as serve_shape_plug_test.exs
does) instead of hand-rolled URI.encode_www_form/1 interpolation, and hoist
the stub inspector into an @inspector module attribute, matching the other
plug tests.

Also move the explanatory comment inside validate_request/2 so it sits with
the Map.take/2 it describes, and restore the changeset entry required by the
Check Changeset workflow for any PR touching packages/sync-service.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The hand-maintained `Map.take` list duplicated the field list of the
`Api.Params` Ecto schema, and that duplication is what caused the
original bug: the list silently rotted as new shape-defining parameters
were added. Ecto's `cast` already drops unknown parameters, and
`validate_for_delete/2` deliberately ignores request-only fields such as
`offset` and `live`, so the plug can pass the merged query/path params
through wholesale.

Also remove the `Map.put("offset", "-1")` — nothing on the delete path
reads `offset`; it is a leftover from when the delete plug reused the
general `Params.validate/2`.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Request-only params such as `live` are ignored by delete validation but
still go through schema casting, so a malformed value returns a 400
instead of being silently dropped. Pin that down as expected behaviour.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@alco alco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! I've adjusted the implementation a bit for future-proofing.

@netlify

netlify Bot commented Aug 12, 2026

Copy link
Copy Markdown

✅ Deploy Preview for electric-next ready!

Name Link
🔨 Latest commit d535d21
🔍 Latest deploy log https://app.netlify.com/projects/electric-next/deploys/6a7c492cad46be00086537ae
😎 Deploy Preview https://deploy-preview-4754--electric-next.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.21%. Comparing base (2a7f65a) to head (d535d21).
⚠️ Report is 4 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4754      +/-   ##
==========================================
- Coverage   60.01%   59.21%   -0.81%     
==========================================
  Files         397      379      -18     
  Lines       43766    42653    -1113     
  Branches    12588    12335     -253     
==========================================
- Hits        26268    25257    -1011     
+ Misses      17416    17354      -62     
+ Partials       82       42      -40     
Flag Coverage Δ
packages/agents 72.64% <ø> (ø)
packages/agents-mcp 77.70% <ø> (ø)
packages/agents-mobile 80.67% <ø> (ø)
packages/agents-runtime 83.73% <ø> (ø)
packages/agents-server 75.47% <ø> (ø)
packages/agents-server-ui 8.32% <ø> (ø)
packages/electric-ax 51.06% <ø> (ø)
packages/experimental ?
packages/react-hooks ?
packages/start 82.83% <ø> (ø)
packages/typescript-client ?
packages/y-electric 56.05% <ø> (ø)
typescript 59.21% <ø> (-0.81%) ⬇️
unit-tests 59.21% <ø> (-0.81%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alco
alco merged commit 2171ca1 into electric-sql:main Aug 12, 2026
57 of 63 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been released! 🚀

The following packages include changes from this PR:

  • @core/sync-service@1.7.11

Thanks for contributing to Electric!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants