Skip to content

Commit

Permalink
Fix inspecting dynamic/2 with interpolated named bindings (#4541)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-rychlewski authored Nov 3, 2024
1 parent 98ba6fe commit d47bc2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/ecto/query/inspect.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ alias Ecto.Query.{DynamicExpr, JoinExpr, QueryExpr, WithExpr, LimitExpr}

defimpl Inspect, for: Ecto.Query.DynamicExpr do
def inspect(%DynamicExpr{binding: binding} = dynamic, opts) do
binding =
Enum.map(binding, fn
{{:^, _, [as]}, bind} when is_atom(as) -> {as, bind}
other -> other
end)

dynamic = %{dynamic | binding: binding}

joins =
binding
|> Enum.drop(1)
Expand Down
3 changes: 3 additions & 0 deletions test/ecto/query/inspect_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ defmodule Ecto.Query.InspectTest do
assert inspect(dynamic([comments: c], c.bar == ^1)) ==
"dynamic([comments: c], c.bar == ^1)"

assert inspect(dynamic([{^:comments, c}], c.bar == ^1)) ==
"dynamic([comments: c], c.bar == ^1)"

dynamic = dynamic([p], p.bar == ^1)

assert inspect(dynamic([p], ^dynamic and p.foo == ^0)) ==
Expand Down

0 comments on commit d47bc2c

Please sign in to comment.