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

Getting microseconds error #14

Open
spapas opened this issue May 2, 2019 · 7 comments
Open

Getting microseconds error #14

spapas opened this issue May 2, 2019 · 7 comments
Assignees
Labels

Comments

@spapas
Copy link

spapas commented May 2, 2019

Hello, I am trying to integrate ex_audit wit my application using more or less the default configuration.

However when I try to save a model with changes I get the following error:

:utc_datetime expects microseconds to be empty, got: #DateTime<2019-05-02 05:19:39.935000Z>
Use `DateTime.truncate(utc_datetime, :second)` (available in Elixir v1.6+) to remove microseconds.

lib/ecto/type.ex
  end
  defp check_no_usec!(%{microsecond: {0, 0}} = datetime, _kind), do: datetime
  defp check_no_usec!(%struct{} = datetime, kind) do
    raise ArgumentError, """
    #{inspect(kind)} expects microseconds to be empty, got: #{inspect(datetime)}
    Use `#{inspect(struct)}.truncate(#{kind}, :second)` (available in Elixir v1.6+) to remove microseconds.
    """
  end

Any suggestions on how to fix ?

Here are the versions I use:

...  
  ecto 3.1.1
  ecto_sql 3.1.1
  ex_audit 0.6.0
  phoenix 1.4.3
  phoenix_ecto 4.0.0

Also here's the whole ST:

 ecto lib/ecto/type.ex:1224 Ecto.Type.check_no_usec!/2
 ecto lib/ecto/type.ex:412 Ecto.Type.dump_utc_datetime/1
 ecto lib/ecto/type.ex:817 Ecto.Type.process_dumpers/3
 ecto lib/ecto/repo/schema.ex:925 Ecto.Repo.Schema.dump_field!/6
 ecto lib/ecto/repo/schema.ex:109 anonymous fn/5 in Ecto.Repo.Schema.init_mapper/3
 elixir lib/enum.ex:1437 anonymous fn/3 in Enum.map_reduce/3
 stdlib maps.erl:257 :maps.fold_1/3
 elixir lib/enum.ex:1956 Enum.map_reduce/3
 ecto lib/ecto/repo/schema.ex:81 anonymous fn/5 in Ecto.Repo.Schema.extract_header_and_fields/5
 elixir lib/enum.ex:1431 Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
 ecto lib/ecto/repo/schema.ex:80 Ecto.Repo.Schema.extract_header_and_fields/5
 ecto lib/ecto/repo/schema.ex:44 Ecto.Repo.Schema.do_insert_all/6
 ex_audit lib/repo/schema.ex:34 anonymous fn/4 in ExAudit.Schema.update/4
 ex_audit lib/repo/schema.ex:155 ExAudit.Schema.run_in_multi/4
 ecto lib/ecto/multi.ex:579 Ecto.Multi.apply_operation/5
 elixir lib/enum.ex:1940 Enum."-reduce/3-lists^foldl/2-0-"/3
 ecto lib/ecto/multi.ex:563 anonymous fn/5 in Ecto.Multi.apply_operations/5
 ecto_sql lib/ecto/adapters/sql.ex:874 anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4
 db_connection lib/db_connection.ex:1415 DBConnection.run_transaction/4
 ecto lib/ecto/repo/transaction.ex:15 Ecto.Repo.Transaction.transaction/4

Thanks !

@spapas
Copy link
Author

spapas commented May 2, 2019

Please notice that this issue can be resolved by changing line 56 of ex_audit/lib/tracking/tracking.ex:

from
now = DateTime.utc_now()
to
now = DateTime.utc_now() |> DateTime.truncate(:second)

@narrowtux
Copy link
Contributor

I see, the problem is it needs to be configurable because some people are using the _usec variants of the datetimes.

@narrowtux narrowtux self-assigned this May 7, 2019
@spapas
Copy link
Author

spapas commented May 15, 2019

Hello @narrowtux, do you have any timeline on when will this bug be fixed?

TIA

@aerosol
Copy link

aerosol commented May 17, 2019

You can solve this by migrating your recorded_at to :utc_datetime_usec

@spapas
Copy link
Author

spapas commented May 17, 2019

Thanks @aerosol ... I was solving it till now by actually implementing the solution I described in my previous comment (#14 (comment))

@ashneyderman
Copy link

ashneyderman commented May 26, 2019

@spapas - @aerosol suggestion required no code change at all in the library's code base - you only change the schema in your code base. As was noted in #14 (comment) this needs to be configurable. I.e some people will want microseconds others will not (although, I think a smart thing to do here is to stick with as much precision as possible).

@spapas
Copy link
Author

spapas commented May 27, 2019

Well at least you need to add a small clarification in the README to help any new users having this issue.

@narrowtux narrowtux added the bug label Nov 15, 2020
neodevelop added a commit to neodevelop/ex_audit that referenced this issue Jan 12, 2021
neodevelop added a commit to neodevelop/ex_audit that referenced this issue Jan 12, 2021
neodevelop added a commit to neodevelop/ex_audit that referenced this issue Jan 12, 2021
neodevelop added a commit to neodevelop/ex_audit that referenced this issue Mar 20, 2021
neodevelop added a commit to neodevelop/ex_audit that referenced this issue Mar 20, 2021
neodevelop added a commit to neodevelop/ex_audit that referenced this issue Mar 20, 2021
neodevelop added a commit to neodevelop/ex_audit that referenced this issue Mar 20, 2021
neodevelop added a commit to neodevelop/ex_audit that referenced this issue Mar 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants