(Postgrex.QueryError) type `money` can not be handled by the types module Postgrex.DefaultTypes

Hello guys! I’m experiencing something weird. I’m using two composite types in two different project, in one it works out of the box but not the other.

The first one defines a composite field for a Fraction with (numerator, denominator), works fine. The second defines a money type (amount, current), just like the Money lib says to use the composite field but I get the following error when trying to fetch record.

     ** (Postgrex.QueryError) type `money` can not be handled by the types module Postgrex.DefaultTypes

The project that works:

The project that doesn’t work:

The only differences I see in both is the one that works uses the type in the actual project and is a Phoenix app, the other is a lib and only use the type in tests (I’m not using the money lib because it’s only for testing that I need a composite field) (modifié)

On a first glance, you should not define anything that is used throughout the entire project inside test/support. That path is normally only compiled in test environment.

I haven’t 100% traced out how the repo gets started in the Loupe project, but my guess right now is that it’s happening at an unexpected time and causing the Postgrex “bootstrap” to not see the money composite type’s OID when it loads up its internal cache.

It’s not used throughout the project, only for testing purposes so I think it goes in support.

That’s an interesting take. The test_helpers.exs file ensure that ecto is started then it gets started in test_case.ex as a setup step for the test cases.

Not gonna lie I did a couple of back and forth with the test setup to have postgres working and it took me some iteration to have something that works in a decent way so I might have something sketch in the test case setup.

Thanks for pointing me in the right direction. I don’t have a solution per se to my problem, but it’s most likely due to something like that since if I just use the money library, it works fine. So it’s probably compiled before the Postgrex gets bootstrap and works.

If someone wants to have a shot at how to make it work with a test-only lib, I’m happy to try and test it, but extending a type that is already compiled at the time of writing tests works.