summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-11-29 10:50:44 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2019-11-29 10:54:12 -0500
commitbb338b91752f4f758edd9b2549a228e891596ae0 (patch)
treee92e30b621c41bf4ce706cb04c90f99cc6fa8cd9 /lib/sqlalchemy/testing
parent06b0892da049a995ee4cd1e7cc3c1eb68f3dde64 (diff)
downloadsqlalchemy-bb338b91752f4f758edd9b2549a228e891596ae0.tar.gz
Gracefully degrade for SQLite JSON receiving direct numeric value
Fixed issue to workaround SQLite's behavior of assigning "numeric" affinity to JSON datatypes, first described at :ref:`change_3850`, which returns scalar numeric JSON values as a number and not as a string that can be JSON deserialized. The SQLite-specific JSON deserializer now gracefully degrades for this case as an exception and bypasses deserialization for single numeric values, as from a JSON perspective they are already deserialized. Also adds a combinatoric fixture for JSON single values within the dialect-general test suite. Fixes: #5014 Change-Id: Id38221dce1271fec527ca198b23908547b25d8a0
Diffstat (limited to 'lib/sqlalchemy/testing')
-rw-r--r--lib/sqlalchemy/testing/suite/test_types.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/sqlalchemy/testing/suite/test_types.py b/lib/sqlalchemy/testing/suite/test_types.py
index bf5b18d0e..2a5dad2d6 100644
--- a/lib/sqlalchemy/testing/suite/test_types.py
+++ b/lib/sqlalchemy/testing/suite/test_types.py
@@ -827,6 +827,38 @@ class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest):
# make sure we get a row even if value is None
eq_(row, (value,))
+ @testing.combinations(
+ (True,),
+ (False,),
+ (None,),
+ (15,),
+ (0,),
+ (-1,),
+ (-1.0,),
+ (15.052,),
+ ("a string",),
+ (util.u("réve illé"),),
+ (util.u("réve🐍 illé"),),
+ )
+ def test_single_element_round_trip(self, element):
+ data_table = self.tables.data_table
+ data_element = element
+ with config.db.connect() as conn:
+ conn.execute(
+ data_table.insert(),
+ {
+ "name": "row1",
+ "data": data_element,
+ "nulldata": data_element,
+ },
+ )
+
+ row = conn.execute(
+ select([data_table.c.data, data_table.c.nulldata])
+ ).first()
+
+ eq_(row, (data_element, data_element))
+
def test_round_trip_custom_json(self):
data_table = self.tables.data_table
data_element = {"key1": "data1"}