]> 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>
Fri, 25 Oct 2019 17:10:30 +0000 (13:10 -0400)
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

test/requirements.py

index 739f90b9551953440464ae3edd63759d2f8a05fc..bd6fc8133d7ffcf4f5f1c46c7d4f310926d243b8 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
@@ -816,10 +817,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(