I have a resource with a custom type DateTimeUsec that implements the following function:
def cast_stored(value, _) do
value = DateTime.shift_zone!(value, "America/Sao_Paulo")
{:ok, value}
end
When I create a record, the cast_stored function is called and the field is in the correct timezone. When I update the DateTimeUsec field, the cast_stored function is not called and the field remains in UTC timezone.
what happens if you update to the latest ash_postgres
?
Same problem with ash_postgres 1.15.26.
If you could work up a reproduction in an ash_postgres test that would be great. Will need to investigate
Zach, to reproduce the problem, clone the project GitHub - tellesleandro/ash_tests: Tests for the Ash Framework and run the tests.
Ah, I didn’t put it together that you aren’t on the 3.0. I will back port a fix for this.
try out ash_postgres 1.5.27
It works, Zach. Thanks. There’s a small side effect. When updating the record, it shows on console (in the middle of the test outputs) the list [:id, :updated_at, :field_1]
.
[debug] QUERY OK db=0.5ms idle=1001.8ms
begin []
↳ anonymous fn/3 in Ash.Changeset.with_hooks/3, at: lib/ash/changeset/changeset.ex:2544
[:id, :updated_at, :field_1]
[debug] QUERY OK source="table_1" db=2.4ms
UPDATE "table_1" AS t0 SET "updated_at" = $1, "field_1" = $2 WHERE (t0."id" = $3) RETURNING t0."id", t0."updated_at", t0."field_1" [~U[2024-05-28 13:56:54.638307Z], ~U[2024-05-28 13:56:54.631481Z], "d661f0d2-8e58-4be5-aeef-574db6b95d56"]
↳ AshPostgres.DataLayer.update/2, at: lib/data_layer.ex:2648
[debug] QUERY OK db=2.6ms
commit []
↳ anonymous fn/3 in Ash.Changeset.with_hooks/3, at: lib/ash/changeset/changeset.ex:2544