Ecto: Error while retrieving utc_datetime column from postgresql

Created on 31 May 2017  路  9Comments  路  Source: elixir-ecto/ecto

Environment

  • Elixir version (elixir -v): 1.4.4
  • Database and version (PostgreSQL 9.4, MongoDB 3.2, etc.): Postgresql 9.5
  • Ecto version (mix deps): Ecto 2.0 (in mix deps)
  • Database adapter and version (mix deps): postgrex, "~> 0.11"
  • Operating system: Linux Ubuntu 16.04

Current behavior

%Inspect.Error{message: "got UndefinedFunctionError with message \"function Inspect.DateTime.inspect/2 is undefined (module Inspect.DateTime is not available)\" while inspecting %{__struct__: DateTime, calendar: Calendar.ISO, day: 31, hour: 10, microsecond: {806000, 6}, minute: 6, month: 5, second: 42, std_offset: 0, time_zone: \"Etc/UTC\", utc_offset: 0, year: 2017, zone_abbr: \"UTC\"}"}

Expected behavior

%DateTime{calendar: Calendar.ISO, day: 31, hour: 11, microsecond: {450449, 6},
 minute: 25, month: 5, second: 38, std_offset: 0, time_zone: "Etc/UTC",
 utc_offset: 0, year: 2017, zone_abbr: "UTC"}

when i am trying to convert, utc_datetime(Ecto data type) from postgresql, it is giving above current behaviour. i am not able to understand why it is happening.

I am building release, after that it is returning like this. when i do run release with console, and try to do DateTime.utc_now(), it is giving me the same error.

thank you in advance.

Bug Needs more info

Most helpful comment

This was indeed related to a bug in Elixir: https://github.com/elixir-lang/elixir/issues/5987

It is permanently fixed in the 1.5 release. For earlier releases recompiling the project withmix compile --force should fix the issue temporarily.

All 9 comments

Hrm, something unexpected is happening. It should not try to invoke Inspect.DateTime because Inspect.DateTime does not implement such protocol. Maybe something wrong is happening during protocol consolidation or during releases?

  1. If you remove _build and compile again, can you still reproduce it inside a release?
  2. Can you reproduce it by running MIX_ENV=prod iex -S mix?
  3. Or can you isolate the error in an application we would be able to try out?

Doesn't timex or calendar implement Inspect for DateTime? Are you using one of them? Also, are you using an umbrella?

yes, i am using umbrella app. and no i am not using timex, this is pure DateTime and for ecto it is :utc_datetime datatype column. @michalmuskala

@josevalim I tried deleting _build and then generating release again. same error.

@i-m-v-j can you reproduce it using only mix (without releases)? And can you isolate the bug or provide me private access to the application so we can try it out? We suspect this may be related to an Elixir bug with protocols.

same error here. Had umbrella app. Trying to build DateTime struct like this
%DateTime{ year: 2017, month: 6, day: 14, hour: 13, minute: 53, second: 20, microsecond: {0, 0}, time_zone: "Etc/UTC", zone_abbr: "UTC", utc_offset: 0, std_offset: 0 }
got same errors as @0freeman00
Elixir version 1.4.0
will provide more details soon

This was indeed related to a bug in Elixir: https://github.com/elixir-lang/elixir/issues/5987

It is permanently fixed in the 1.5 release. For earlier releases recompiling the project withmix compile --force should fix the issue temporarily.

No, i don't think it is bug. because in my case, i was trying to convert nil value to date. so that is why it was throwing error. so, @mkaravaev please check and make sure you are by mistake not trying to convert date of nil value.

The error that was in the initial report message - Inspect.Error instead of the proper output is exactly because of this bug.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yordis picture yordis  路  4Comments

jordi-chacon picture jordi-chacon  路  4Comments

jbence picture jbence  路  3Comments

stavro picture stavro  路  4Comments

fuelen picture fuelen  路  3Comments