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

(Ecto.ChangeError) value {{YYYY, M, D}, {0, 0, 0, 0}} for ... in insert does not match type Timex.Ecto.DateTime #32

Open
markshiz opened this issue Jun 5, 2016 · 6 comments

Comments

@markshiz
Copy link

markshiz commented Jun 5, 2016

Getting the following error:

    ** (Ecto.ChangeError) value `{{2016, 9, 3}, {0, 0, 0, 0}}` for `App.Session.expiration` in `insert` does not match type Timex.Ecto.DateTime
        (ecto) lib/ecto/query/planner.ex:33: anonymous fn/6 in Ecto.Query.Planner.fields/4
        (stdlib) lists.erl:1262: :lists.foldl/3
        (ecto) lib/ecto/query/planner.ex:21: Ecto.Query.Planner.fields/4
        (ecto) lib/ecto/repo/schema.ex:449: Ecto.Repo.Schema.dump_changes/5
        (ecto) lib/ecto/repo/schema.ex:77: anonymous fn/11 in Ecto.Repo.Schema.do_insert/4
        (ecto) lib/ecto/repo/schema.ex:477: anonymous fn/3 in Ecto.Repo.Schema.wrap_in_transaction/9
        (ecto) lib/ecto/pool.ex:292: Ecto.Pool.with_rollback/3
        (ecto) lib/ecto/adapters/sql.ex:582: Ecto.Adapters.SQL.transaction/8
        (ecto) lib/ecto/pool.ex:244: Ecto.Pool.outer_transaction/6
        (ecto) lib/ecto/adapters/sql.ex:551: Ecto.Adapters.SQL.transaction/3

With the following model:

defmodule App.Session do
  use App.Web, :model
  use Timex

  schema "sessions" do
    field :key, :string
    field :expiration, Timex.Ecto.DateTime

    timestamps
  end

  @required_fields ~w(key expiration)
  @optional_fields ~w()

  def changeset(model, params \\ :empty) do
    model
    |> cast(params, @required_fields, @optional_fields)
  end

  def update_key_changeset(model) do
    changeset( model, %{ key: 'key', expiration: Date.now |> Date.shift(days: 90) })
  end
end

Here are my versions

$ mix hex.outdated
Dependency           Current  Latest  Requirement
phoenix              1.1.6    1.1.6   ~> 1.1.6
phoenix_ecto         2.0.2    2.0.2   ~> 2.0.2
timex                2.1.6    2.1.6   ~> 2.1.6
timex_ecto           1.1.1    1.1.1   ~> 1.1.1
@bitwalker
Copy link
Owner

Well that's odd, it's calling dump with {{2016, 9, 3}, {0, 0, 0, 0}} instead of a DateTime. I can add an overload to dump which just takes in such a date/time tuple and passes it through, but I wonder what that just started happening. What version of Ecto are you using?

@markshiz
Copy link
Author

markshiz commented Jun 7, 2016

I'm on the latest stable version, 1.1.8

@bitwalker
Copy link
Owner

My tests show this is now working in the latest release, 1.1.3. I'll close this for now, but please reopen if you are still encountering issues. Thanks!

@markshiz
Copy link
Author

markshiz commented Jun 16, 2016

I just updated timex_ecto and elixir to latest versions, but I'm still running into the same issue.

** (exit) an exception was raised:
    ** (Ecto.ChangeError) value `{{2016, 9, 14}, {0, 0, 0, 0}}` for `App.Session.expiration` in `insert` does not match type Timex.Ecto.DateTime
        (ecto) lib/ecto/query/planner.ex:33: anonymous fn/6 in Ecto.Query.Planner.fields/4
        (stdlib) lists.erl:1262: :lists.foldl/3
        (ecto) lib/ecto/query/planner.ex:21: Ecto.Query.Planner.fields/4
        (ecto) lib/ecto/repo/schema.ex:449: Ecto.Repo.Schema.dump_changes/5
        (ecto) lib/ecto/repo/schema.ex:77: anonymous fn/11 in Ecto.Repo.Schema.do_insert/4
        (ecto) lib/ecto/repo/schema.ex:477: anonymous fn/3 in Ecto.Repo.Schema.wrap_in_transaction/9
        (ecto) lib/ecto/pool.ex:292: Ecto.Pool.with_rollback/3
        (ecto) lib/ecto/adapters/sql.ex:582: Ecto.Adapters.SQL.transaction/8
        (ecto) lib/ecto/pool.ex:244: Ecto.Pool.outer_transaction/6
        (ecto) lib/ecto/adapters/sql.ex:551: Ecto.Adapters.SQL.transaction/3
Dependency           Current  Latest  Requirement
phoenix              1.1.6    1.1.6   ~> 1.1.6
phoenix_ecto         2.0.2    2.0.2   ~> 2.0.2
phoenix_html         2.5.1    2.5.1   ~> 2.5.1
phoenix_live_reload  1.0.5    1.0.5   ~> 1.0.5
postgrex             0.11.1   0.11.1  >= 0.0.0
timex                2.1.6    2.1.6   ~> 2.1.6
timex_ecto           1.1.3    1.1.3   ~> 1.1.3
Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Elixir 1.2.6

@bitwalker bitwalker reopened this Jun 16, 2016
@bitwalker
Copy link
Owner

@markshiz Ok, I've reopened this. What version of Ecto are you running?

@markshiz
Copy link
Author

ecto is the latest non-beta, 1.1.8

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

No branches or pull requests

2 participants