travisf

travisf

Ecto update tests failing due to :utc_datetime_usec

I recently upgraded a project from Ecto 2~ to Ecto 3. I was able to get all tests passing locally, there were a few instances were tests were failing due to microsecond precision so I added @trimestamps_opts [type: :utc_datetime_usec] and everything worked.

However, when I run tests in Docker (via Bitbucket pipelines) I get this error:

  1) test list/0 returns all vendors .../vendors/vendors_test.exs:36
     Assertion with == failed
     code:  assert expected == [actual]
     left:  [
              %Vendor{
                __meta__: #Ecto.Schema.Metadata<:loaded, "vendors">,
                cut_off_time: ~T[12:00:00],
                email: nil,
                holidays: [],
                id: 3,
                inserted_at: ~N[2022-11-10 00:30:35.000000],
                key: "Vendor 3",
                lead_time: 2,
                name: "Vendor 11",
                timezone: "US/Eastern",
                updated_at: ~N[2022-11-10 00:30:35.000000]
              }
            ]
     right: [
              %Vendor{
                __meta__: #Ecto.Schema.Metadata<:loaded, "vendors">,
                cut_off_time: ~T[12:00:00],
                email: nil,
                holidays: [],
                id: 3,
                inserted_at: ~N[2022-11-10 00:30:34.544646],
                key: "Vendor 3",
                lead_time: 2,
                name: "Vendor 11",
                timezone: "US/Eastern",
                updated_at: ~N[2022-11-10 00:30:34.544646]
              }
            ]
     stacktrace:
       ...vendors/vendors_test.exs:39: (test)

This is the particular test in question:

  test "list/0 returns all vendors" do
    actual = insert(:vendor)
    expected = Vendors.list()
    assert expected == [actual]
  end

To me, this looks as if ExMachina is creating a vendor with a datetime utc_datetime_usec that respects microseconds, but it is not being persisted into the database as such? Again, this test gives me no trouble locally it’s only when the test runs via Docker while deploying.

Marked As Solved

LostKobrakai

LostKobrakai

You’d want to make sure to change your migrations to _usec types as well. Postgres allows setting a precision on timestamp columns and ecto started to use that at some point.

Where Next?

Popular in Questions Top

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New

We're in Beta

About us Mission Statement