Skip to content

Commit 7831ce1

Browse files
committed
test: add unit test for empty bound IN list sentinel clause
1 parent f8f2b6a commit 7831ce1

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

test/ecto_connection_test.exs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,33 @@ defmodule Ecto.Adapters.LibSql.ConnectionTest do
632632

633633
assert sql =~ ~s["id" IN (?2, ?3)]
634634
end
635+
636+
test "empty bound IN list generates always-false sentinel" do
637+
# Simulates: where(query, [u], u.id in ^[])
638+
# After Ecto planning, the empty list becomes {:^, _, [0, 0]}.
639+
query = %Ecto.Query{
640+
from: %Ecto.Query.FromExpr{source: {"users", nil}},
641+
sources: {{"users", nil, nil}},
642+
select: %Ecto.Query.SelectExpr{fields: [{:&, [], [0]}]},
643+
wheres: [
644+
%Ecto.Query.BooleanExpr{
645+
op: :and,
646+
expr:
647+
{:in, [],
648+
[
649+
{{:., [], [{:&, [], [0]}, :id]}, [], []},
650+
{:^, [], [0, 0]}
651+
]},
652+
params: []
653+
}
654+
]
655+
}
656+
657+
sql = Connection.all(query) |> IO.iodata_to_binary()
658+
659+
# SQLite rejects IN () so the zero-length guard emits an always-false subquery.
660+
assert sql =~ ~s["id" IN (SELECT NULL WHERE 1=0)]
661+
end
635662
end
636663

637664
describe "on_conflict insert" do

0 commit comments

Comments
 (0)