Unable to encode nil values
eamonpenland opened this issue · comments
getting this error for nil values,
unable to encode value: {nil, "t_reservation"}
Could you show, what you do exact?
sure.
This is in the controller
def manage(conn, %{"username" => username, "property_nickname" => nickname}) do
[property] = Assets.get_property_by_nickname!(nickname)
conn = put_gon(conn, controller: property)
render(conn, "manage.html", username: username, property_nickname: nickname, property: property)
end
and this is the structure of property
%Bb.Assets.Property{__meta__: #Ecto.Schema.Metadata<:loaded, "t_property">,
calendar: [], cc_3166_2: nil, city: "Bristol", country: nil,
currency_4217: nil, deleted_at: nil, id: 11,
inserted_at: ~N[2017-07-02 19:07:18.051768], nickname: "secret_lair",
owner_id: 1, postal: "06010", price_day: 1.0, price_month: 100.0,
price_week: 10.0, state: "CT", street: "2034 Meadow View Drive", street2: nil,
t_reservation: [%Bb.Assets.Reservation{__meta__: #Ecto.Schema.Metadata<:loaded, "t_reservation">,
calendar: #Ecto.Association.NotLoaded<association :calendar is not loaded>,
checkin: nil, checkout: nil, deleted_at: nil, from_date: nil, guests: [],
hash: "EWMUUSN7SRGGH5PGL2I6TKSNZUMTDNMN5IFIE3P2QMWWL26TXJAA====", id: 2,
inserted_at: ~N[2017-07-02 19:22:15.223132], is_agreed: false,
is_paid: false, price_day: 1.0, price_month: 1.0, price_week: 1.0,
property: #Ecto.Association.NotLoaded<association :property is not loaded>,
property_id: 11, to_date: nil, updated_at: ~N[2017-07-02 19:22:15.239044]}],
t_user: #Ecto.Association.NotLoaded<association :t_user is not loaded>,
updated_at: ~N[2017-07-02 19:07:18.051776]}
Did you try to put property to conn via in this way put_gon(conn, :controller, property)
? Problem can be here https://github.com/khusnetdinov/phoenix_gon/blob/master/lib/phoenix_gon/controller.ex#L19
just tried that...still same error. I did fork the package and upgraded to {:poison, "~> 3.1.0"},
Well, I need to understand where is problem, and why nil value appear here. Need more information for investigate problem. Could you share you code or move this code to isolate project with possibility to share?
I think, this problem relates to Ecto encoding problem. I found this https://stackoverflow.com/questions/32549712/encoding-a-ecto-model-to-json-in-elixir/32553676, https://coderwall.com/p/fhsehq/fix-encoding-issue-with-ecto-and-poison and this elixir-ecto/ecto#840 could you check if it relates to you problem?
ahh. you're right! Thanks! Also, thanks for making the package. Really appreciate it.