elixir-sqlite / ecto_sqlite3

An Ecto SQLite3 adapter.
https://hexdocs.pm/ecto_sqlite3
MIT License
300 stars 45 forks source link

FunctionClauseError after Ecto v3.12 update #146

Closed sorentwo closed 3 months ago

sorentwo commented 3 months ago

The recent Ecto v3.12 update seems to have broken distinct queries. Here's a full stacktrace, taken from the dependabot update to the Oban repo:

** (FunctionClauseError) no function clause matching in Ecto.Adapters.SQLite3.Connection.distinct/3
    (ecto_sqlite3 0.16.0) lib/ecto/adapters/sqlite3/connection.ex:846: Ecto.Adapters.SQLite3.Connection.distinct(%Ecto.Query.ByExpr{expr: true, file: "/home/runner/work/oban/oban/lib/oban/engines/basic.ex", line: 178, params: nil, subqueries: []}, {{[[34, "oban_jobs", 34]], [111 | "0"], Oban.Job}, []}, #Ecto.Query<from j0 in Oban.Job, where: j0.state == "available", where: not is_nil(j0.queue), distinct: true, select: j0.queue>)
    (ecto_sqlite3 0.16.0) lib/ecto/adapters/sqlite3/connection.ex:859: Ecto.Adapters.SQLite3.Connection.select/2
    (ecto_sqlite3 0.16.0) lib/ecto/adapters/sqlite3/connection.ex:178: Ecto.Adapters.SQLite3.Connection.all/2
    (ecto_sqlite3 0.16.0) lib/ecto/adapters/sqlite3.ex:187: Ecto.Adapters.SQLite3.prepare/2
    (ecto 3.12.0) lib/ecto/query/planner.ex:202: Ecto.Query.Planner.query_without_cache/4
    (ecto 3.12.0) lib/ecto/query/planner.ex:170: Ecto.Query.Planner.query_prepare/6
    (ecto 3.12.0) lib/ecto/query/planner.ex:143: Ecto.Query.Planner.query_with_cache/8
    (ecto 3.12.0) lib/ecto/repo/queryable.ex:214: Ecto.Repo.Queryable.execute/4
    (ecto 3.12.0) lib/ecto/repo/queryable.ex:19: Ecto.Repo.Queryable.all/3
    (oban 2.18.0) lib/oban/engines/basic.ex:180: Oban.Engines.Basic.check_available/1
    (oban 2.18.0) lib/oban/engine.ex:264: anonymous fn/2 in Oban.Engine.check_available/1
    (oban 2.18.0) lib/oban/engine.ex:339: anonymous fn/3 in Oban.Engine.with_span/4
    (telemetry 1.2.1) /home/runner/work/oban/oban/deps/telemetry/src/telemetry.erl:321: :telemetry.span/3
    (oban 2.18.0) lib/oban/stager.ex:88: Oban.Stager.notify_queues/1
    (oban 2.18.0) lib/oban/stager.ex:73: anonymous fn/1 in Oban.Stager.stage_and_notify/2
    (ecto_sql 3.12.0) lib/ecto/adapters/sql.ex:1382: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4
    (db_connection 2.7.0) lib/db_connection.ex:1756: DBConnection.run_transaction/4
    (oban 2.18.0) lib/oban/repo.ex:156: Oban.Repo.transaction/4
    (oban 2.18.0) lib/oban/stager.ex:70: Oban.Stager.stage_and_notify/2
    (oban 2.18.0) lib/oban/stager.ex:57: anonymous fn/2 in Oban.Stager.handle_info/2

Here's a link to the failing CI run: https://github.com/sorentwo/oban/actions/runs/10359975065/job/28677500392?pr=1135

warmwaffles commented 3 months ago

Yea I think I remember seeing something upstream about the distinct changes. I'll try to get this resolved soon.

warmwaffles commented 3 months ago

Leaving this here for later https://github.com/elixir-ecto/ecto_sql/pull/607

warmwaffles commented 3 months ago

Fix released under v0.17.0

sorentwo commented 3 months ago

I can confirm that fixed the issue and got the upgrade passing. Thanks for the quick fix!