Skip to content

ChangesetParser.extract_messages breaks with tuple types #6

@d-webs

Description

@d-webs

I am getting the below error from AbsintheErrorPayload

Request: POST /v2/graphql
** (exit) an exception was raised:
    ** (Protocol.UndefinedError) protocol String.Chars not implemented for {:array, :map}. This protocol is implemented for: Postgrex.Copy, Postgrex.Query, Decimal, Float, DateTime, Time, List, Version.Requirement, Atom, Integer, Version, Date, BitString, NaiveDateTime, URI
        (elixir) /home/build/elixir/lib/elixir/lib/string/chars.ex:3: String.Chars.impl_for!/1
        (elixir) /home/build/elixir/lib/elixir/lib/string/chars.ex:22: String.Chars.to_string/1
        (absinthe_error_payload) lib/absinthe_error_payload/changeset_parser.ex:114: anonymous fn/2 in AbsintheErrorPayload.ChangesetParser.interpolate_message/1
        (elixir) lib/enum.ex:1940: Enum."-reduce/3-lists^foldl/2-0-"/3
        (absinthe_error_payload) lib/absinthe_error_payload/changeset_parser.ex:93: AbsintheErrorPayload.ChangesetParser.construct_message/2
        (ecto) lib/ecto/changeset.ex:2717: anonymous fn/4 in Ecto.Changeset.merge_error_keys/3
        (elixir) lib/enum.ex:1940: Enum."-reduce/3-lists^foldl/2-0-"/3
        (ecto) lib/ecto/changeset.ex:2704: Ecto.Changeset.traverse_errors/2
        (ecto) lib/ecto/changeset.ex:2731: anonymous fn/3 in Ecto.Changeset.merge_related_keys/4
        (elixir) lib/enum.ex:1431: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
        (ecto) lib/ecto/changeset.ex:2730: anonymous fn/4 in Ecto.Changeset.merge_related_keys/4
        (stdlib) maps.erl:257: :maps.fold_1/3
        (ecto) lib/ecto/changeset.ex:2731: anonymous fn/3 in Ecto.Changeset.merge_related_keys/4
        (elixir) lib/enum.ex:1431: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
        (ecto) lib/ecto/changeset.ex:2730: anonymous fn/4 in Ecto.Changeset.merge_related_keys/4
        (stdlib) maps.erl:257: :maps.fold_1/3
        (absinthe_error_payload) lib/absinthe_error_payload/changeset_parser.ex:17: AbsintheErrorPayload.ChangesetParser.extract_messages/1

This looks like it is happening because I have a nested type in my model, like this:

schema "products" do
    # ...
    field(:tags, {:array, :string})
    # ...
    timestamps(type: :utc_datetime_usec)
  end

The {:array, :string} type is breaking the interpolate_messages function, as you cannot automatically cast a tuple to a string

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions