]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Perform an active check for sqlite json extension
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 25 Oct 2019 17:10:30 +0000 (13:10 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 10 Nov 2019 23:26:41 +0000 (18:26 -0500)
Apparently some Python builds may not have json enabled
for sqlite even though version > 3.9, add an active check
for the json functions.

Fixes: #4946
Change-Id: I1a1ce7ef72da8da9ad9576e1281d1df415c6af4f
(cherry picked from commit c2e8b48a668a7ae7c1467a00e44fb1e4daa660a3)

test/requirements.py

index f64ccf53e961e76cccb6be6840d9df5e1a98c559..dd3f88730f6d01e7ae0104ea1f17ad1c36f1c6a8 100644 (file)
@@ -5,6 +5,7 @@
 
 import sys
 
+from sqlalchemy import exc
 from sqlalchemy import util
 from sqlalchemy.testing import exclusions
 from sqlalchemy.testing.exclusions import against
@@ -809,10 +810,26 @@ class DefaultRequirements(SuiteRequirements):
                     )
                 ),
                 "postgresql >= 9.3",
-                "sqlite >= 3.9",
+                self._sqlite_json,
             ]
         )
 
+    def _sqlite_json(self, config):
+        if not against(config, "sqlite >= 3.9"):
+            return False
+        else:
+            with config.db.connect() as conn:
+                try:
+                    return (
+                        conn.scalar(
+                            """select json_extract('{"foo": "bar"}', """
+                            """'$."foo"')"""
+                        )
+                        == "bar"
+                    )
+                except exc.DBAPIError:
+                    return False
+
     @property
     def reflects_json_type(self):
         return only_on(