Problem with Ash.Type.dump_to_native/2 after upgrade to 3.5.41
After upgrading to 3.5.41 my tests fail when there is a "NOT IN" query, apparently where before dump_to_native cas called with the atom (:cancelled) now a string "cancelled" is used causing the postgres query to fail.
This is my custom type:
and this is the now failing code:
And the error in the test as attachment.
8 Replies
It appears that the error started with ash_sql version 0.2.93
According to claude:
The regression is triggered at /Users/herman/Projects/_playground/ash/lib/ash/type/atom.ex:115:
def dump_tonative(value, ) when is_atom(value) do
{:ok, to_string(value)}
end
Root Cause Analysis:
The regression path:
1. ash_sql 0.2.93 introduced evaluate_right() function in commit 3cad640
2. This calls maybe_type_expr() at /Users/herman/Projects/_playground/ash_sql/lib/expr.ex:3411-3418
3. Which wraps expressions in Ash.Query.Function.Type
4. The Type function calls Ash.Type.coerce()
5. Coerce determines the values are atoms and processes them with Ash.Type.Atom.dump_to_native/2
6. This converts :cancelled → "cancelled" at line 115
7. When strings reach TimerStatus.dump_to_native/2, it expects atoms but gets strings
8. Results in Postgrex expected an integer...got "cancelled" error
The issue is that the new Type coercion layer in ash_sql 0.2.93 prematurely converts atoms to strings before they reach custom types that expect to handle the original atom
values.
🤔 interesting
please put together a reproduction, too many moving parts for me to know how to address as it is
I had Claude generate me a project to show the problem, it is at https://github.com/Hermanverschooten/ash_sql_reproduction
GitHub
GitHub - Hermanverschooten/ash_sql_reproduction: Test Repo for Ash ...
Test Repo for Ash SQL problem. Contribute to Hermanverschooten/ash_sql_reproduction development by creating an account on GitHub.
The test currently succeeds because it expects the error, when you downgrade ash_sql to 0.2.92, the tests will fail because there is no error.
Please open an issue as well if you haven't
In what repo?
ash_sql
Or ash_sqlite
Done issue #174 for ash_sql. Thanks for taking the time.