From d47bc2cd9363d624f764733b0418fafb70ace68c Mon Sep 17 00:00:00 2001 From: Greg Rychlewski Date: Sun, 3 Nov 2024 06:47:01 -0500 Subject: [PATCH] Fix inspecting `dynamic/2` with interpolated named bindings (#4541) --- lib/ecto/query/inspect.ex | 8 ++++++++ test/ecto/query/inspect_test.exs | 3 +++ 2 files changed, 11 insertions(+) diff --git a/lib/ecto/query/inspect.ex b/lib/ecto/query/inspect.ex index 3911c9ed3f..b09d2602ee 100644 --- a/lib/ecto/query/inspect.ex +++ b/lib/ecto/query/inspect.ex @@ -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) diff --git a/test/ecto/query/inspect_test.exs b/test/ecto/query/inspect_test.exs index 8ae7040a5d..f2c0f379f7 100644 --- a/test/ecto/query/inspect_test.exs +++ b/test/ecto/query/inspect_test.exs @@ -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)) ==