fix(sync-service): array cast assigns element type instead of array type#4348
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4348 +/- ##
==========================================
- Coverage 59.19% 58.99% -0.20%
==========================================
Files 305 290 -15
Lines 28415 27871 -544
Branches 7495 7496 +1
==========================================
- Hits 16819 16442 -377
+ Misses 11582 11415 -167
Partials 14 14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
icehaunter
approved these changes
May 18, 2026
Contributor
|
This PR has been released! 🚀 The following packages include changes from this PR:
Thanks for contributing to Electric! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
"organization_ids" @> ARRAY[$1]::uuid[]return HTTP 400 (Could not select an operator overload) whenever the innerARRAY[...]constructor contains a non-foldable element (a column ref, or a parameter inside a sub-expression that the parser can't reduce ahead of the outer cast).Electric.Replication.Eval.Parser.as_dynamic_cast/3: the:array_castbranch built aFuncwithtype: extract_base_type_name(target_type)plusmap_over_array_in_pos: 0. So for target{:array, :uuid}it stored.type = :uuidwhile the runtime value is still an array — and the operator-overload lookup (Lookups.pick_concrete_operator_overload/3) reads.typeliterally, can't matchanyarray @> anyarray, and the API surfaces a 400.cast_implicit/3and the ANY/ALL builder set the same misleading scalar type, andtry_applying/1had a wrap-in-{:array, _}kludge at line 1582 to paper over it.This PR changes the convention so
Func.typealways reflects the runtime type of the value the Func produces:as_dynamic_cast/3:array_castbranch now keeps the full target array type.cast_implicit/3array branch now stores{:array, to_type}.handle_any_or_all/2'sbool_arraynow stores{:array, :bool}.try_applying/1drops the conditional wrap.The bug stayed hidden for the all-constant case because
do_maybe_reduce/1foldsARRAY[Const, ...]into aConst{type: {:array, T}, value: [...]}before the outer cast runs; the parser test added in this PR uses a column ref to keep the Array unreduced and exposes the mis-typed Func directly.Test plan
mix test packages/sync-service/test/electric/replication/eval/parser_test.exs— 85 tests, including the new minimal assertion atparser_test.exs:1092mix test packages/sync-service/test/electric/replication/eval/— 227 tests + 6 properties + 3 doctests, 0 failuresmix test packages/sync-service/test/electric/shapes/filter_test.exs— 135 tests, 0 failures (coversarray_field @> const_arrayinclusion-index optimisation)mix test packages/sync-service/test/electric/shapes/querying_test.exs— 28 tests, 0 failures