]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
ensure datatype roundtrips for JSON dialects
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 22 Aug 2025 22:12:13 +0000 (18:12 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 25 Aug 2025 14:09:34 +0000 (10:09 -0400)
commit38dda83a8cc7d1add83f8691c3176161706aca6c
tree0cc0f6ed4620333320e800aaf17bc209b488bc4b
parent6ea5d662c841cba628bbeb197bc68b7301b4aaea
ensure datatype roundtrips for JSON dialects

Improved the behavior of JSON accessors :meth:`.JSON.Comparator.as_string`,
:meth:`.JSON.Comparator.as_boolean`, :meth:`.JSON.Comparator.as_float`,
:meth:`.JSON.Comparator.as_integer` to use CAST in a similar way that
the PostgreSQL, MySQL and SQL Server dialects do to help enforce the
expected Python type is returned.

The :meth:`.JSON.Comparator.as_boolean` method when used on a JSON value on
SQL Server will now force a cast to occur for values that are not simple
`true`/`false` JSON literals, forcing SQL Server to attempt to interpret
the given value as a 1/0 BIT, or raise an error if not possible. Previously
the expression would return NULL.

Fixes: #11074
Change-Id: I5024b78ec2fa6b61a9c6ee176112f1b761eeab98
doc/build/changelog/unreleased_21/11074.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mssql/base.py
lib/sqlalchemy/dialects/sqlite/base.py
lib/sqlalchemy/testing/suite/test_types.py