ecto_sql icon indicating copy to clipboard operation
ecto_sql copied to clipboard

Not dumped values in telemetry events

Open fuelen opened this issue 2 years ago • 0 comments

Elixir version

1.12.2

Database and Version

PostgreSQL 14.1

Ecto Versions

ecto 3.9.2, ecto_sql 3.9.1

Database Adapter and Versions (postgrex, myxql, etc)

postgrex 0.16.0

Current behavior

After updating ecto_sql from 3.9.0 to 3.9.1 I noticed one error in my test suit. Possibly related to https://github.com/elixir-ecto/ecto_sql/pull/455 As I understand, Ecto sends all arguments to telemetry, which are not dumped to native types.

if we have the following type

  defmodule Money.Ecto.Type do
    use Ecto.ParameterizedType

    def type(_params), do: :money_type

    def init(_opts), do: %{}

    def cast(_data, _params), do: {:ok, nil}

    def load(nil, _loader, _params), do: {:ok, nil}

    def load({currency, value}, _loader, _params),
      do: {:ok, %Money{currency: currency, value: value}}

    def dump(nil, _dumper, _params), do: {:ok, nil}
    def dump(data, _dumper, _params), do: {:ok, {data.currency, data.value}}

    def equal?(a, b, _params) do
      a == b
    end
  end

and try to insert a new record with the type above, then the value comes to telemetry as is - Money struct.

Expected behavior

Seems like current behaviour is a new feature, but for https://github.com/fuelen/ecto_dev_logger I'd like to have some way of having native types in order to print SQL counterpart.

fuelen avatar Dec 09 '22 10:12 fuelen