You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
implement cross-type cast tests for all combinations within JSON as_XYZ() operators #11074
as_string() should be tested against all of int / bool / float to always return a string on all backends. as_integer() should be tested to always return an int for a JSON int, float as well as a string that contains an integer, using CAST, same for as_float(), as_boolean().
this was never the expected contract for these methods but it is the apparent behavior for most dialects except SQLite right now.
here's a test suite we can start with to see if this is even feasible. these tests pass 100% for PostgreSQL, where we are using CAST most consistently. the suite fails for mysql and sqlite as there are many casting combinations not accommodated:
Activity
zzzeek commentedon Mar 1, 2024
see also #11065
zzzeek commentedon Mar 1, 2024
consider adding a boolean to the methods "force_cast=True" something like that, indicating this is potentially a type cross-cast
zzzeek commentedon Mar 1, 2024
probably overthinking it though
zzzeek commentedon Mar 1, 2024
here's a test suite we can start with to see if this is even feasible. these tests pass 100% for PostgreSQL, where we are using CAST most consistently. the suite fails for mysql and sqlite as there are many casting combinations not accommodated:
CaselIT commentedon Mar 1, 2024
We can probably also add
sqla-tester commentedon Aug 22, 2025
Mike Bayer has proposed a fix for this issue in the main branch:
ensure datatype roundtrips for JSON dialects https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6125
ensure datatype roundtrips for JSON dialects