Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infinite loop when using "format" as field name #263

Open
mikeni opened this issue Dec 10, 2017 · 3 comments
Open

infinite loop when using "format" as field name #263

mikeni opened this issue Dec 10, 2017 · 3 comments
Labels
1.0.0 1.0.0
Milestone

Comments

@mikeni
Copy link
Contributor

mikeni commented Dec 10, 2017

In dsl.ex, if you have :format as attribute

def default_attributes(serializer, struct, conn) do
serializer.__attributes
|> Enum.map(&({&1, apply(serializer, &1, [struct, conn])}))

you get

warning: Elixir.MyApp.V1.PhotoView.format/3 is deprecated.
Please use JaSerializer.format/4 instead, eg:
JaSerializer.format(Elixir.MyApp.V1.PhotoView, data, conn, opts)

and it seems to infinitely loop

@beerlington beerlington added the 1.0.0 1.0.0 label Dec 22, 2018
@beerlington
Copy link
Contributor

This will be fixed with 1.0.0 when we remove the deprecated function.

@beerlington beerlington added this to the 1.0 milestone May 31, 2019
@coneybeare
Copy link

In the meantime, how can you workaround it to use format as an attribute name?

@beerlington
Copy link
Contributor

@coneybeare you can use the attributes/2 callback to serialize any conflicting keywords like format:

defmodule MySerializer do
  def attributes(record, _conn) do
    Map.take(record, [:format])
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.0.0 1.0.0
Projects
None yet
Development

No branches or pull requests

3 participants