Linuus

Linuus

I’ve just upgraded a Phoenix app to 1.3 and Elixir 1.5.2. Now I get an exception on staging but not locally. I’ve traced it down (after getting some help from @michalmuskala on Slack) to when Poison encodes dates.

I use Poison 3.1, and this is the error I get:

** (Poison.EncodeError) unable to encode value: {0, 6}

    (poison) lib/poison/encoder.ex:383: Poison.Encoder.Any.encode/2

    (poison) lib/poison/encoder.ex:227: anonymous fn/4 in Poison.Encoder.Map.encode/3

    (poison) lib/poison/encoder.ex:228: Poison.Encoder.Map."-encode/3-lists^foldl/2-0-"/3

    (poison) lib/poison/encoder.ex:228: Poison.Encoder.Map.encode/3

    (poison) lib/poison/encoder.ex:227: anonymous fn/4 in Poison.Encoder.Map.encode/3

    (poison) lib/poison/encoder.ex:228: Poison.Encoder.Map."-encode/3-lists^foldl/2-0-"/3

    (poison) lib/poison/encoder.ex:228: Poison.Encoder.Map.encode/3

I only return Maps from my render functions (not using @derive in model/schema).

The Map that fails to encode looks like this:

%{id: 216, images: [%{aspect_ratio: 1.33333, id: 194, urls: %{original: "https://example.com/foo.jpg?v=63674938035", small: "https://example.com/foo.jpg?v=63674938035", thumb: "https://example.com/foo.jpg?v=63674938035"}}], inserted_at: ~N[2017-10-11 10:46:53.000000], tag_list: ["foo", "bar", "baz", "qux"], text: "Some text", thread: %{address: "Address 1", area: 100, district: nil, id: 127, interest_count: 4, internal_id: "23852", location: %{lat: 57.7456204, long: 11.9868868}, lot_size: nil, price: 2500000, property_type: %{id: 3, name: "FooBar"}, realtor: %{avatar_url: "https://example.com/avatar.jpg?v=63674969635", email: "foobar@example.com", first_name: "Foo", id: 78, last_name: "Bar", realtor: true}, rooms: #Decimal<4.0>, status: 2, title: "Some title", user_interest_level: 0, web_url: "https://example.com/threads/127"}, thread_id: 127, updated_at: ~N[2017-10-11 10:46:53.000000]}

And from what I can find it’s the NaiveDateTime that breaks.

Any ideas on how to fix this?

Showing Posts 1 to 5

Linuus

Linuus OP

For now I convert the NaiveDateTime myself with NaiveDateTime.to_iso8601(post.updated_at) etc.

hubertlepicki

hubertlepicki

I suspect it might be a precision issue. If you are using Postgres it can have different settings for precision of timestamps, i.e. how many digits are after dot separating seconds from miliseconds etc. Check out the settings in your Postgres and see documentation here: PostgreSQL: Documentation: 9.1: Date/Time Types

I supect that maybe on your staging environment, you have high precision configured for timestamps. The default can be changed in Postgres’s config file. And that somehow Poison can’t understand such high precision. It’s a guess, I’ll leave it up to you to investigate.

Linuus

Linuus OP

Thank you, that sounds plausible! Will check when I’m back at work.

hubertlepicki

hubertlepicki

Don’t forget to update us here. If this is the case, it’s most likely a bug somewhere either in Elixir or Ecto or Poison that needs to be fixed. This should not happen.

Linuus

Linuus OP

Definitely :+1:

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews