Skip to content

Commit 613f78a

Browse files
authored
[ADD] Make sqlalchemy_extractor compatible with sqlalchemy>=1.4 (#2213)
* [ADD] Make sqlalchemy_extractor compatible with sqlalchemy>=1.4 Signed-off-by: mikekutzma <[email protected]> * Chore: Bump databuilder version to 7.4.6 Signed-off-by: Mike Kutzma <[email protected]> --------- Signed-off-by: mikekutzma <[email protected]> Signed-off-by: Mike Kutzma <[email protected]>
1 parent eb7f45b commit 613f78a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

databuilder/databuilder/extractor/sql_alchemy_extractor.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Any
66

77
from pyhocon import ConfigFactory, ConfigTree
8-
from sqlalchemy import create_engine
8+
from sqlalchemy import create_engine, text
99

1010
from databuilder import Scoped
1111
from databuilder.extractor.base_extractor import Extractor
@@ -62,7 +62,11 @@ def _execute_query(self) -> None:
6262
Create an iterator to execute sql.
6363
"""
6464
if not hasattr(self, 'results'):
65-
self.results = self.connection.execute(self.extract_sql)
65+
results = self.connection.execute(text(self.extract_sql))
66+
# Makes this forward compatible with sqlalchemy >= 1.4
67+
if hasattr(results, "mappings"):
68+
results = results.mappings()
69+
self.results = results
6670

6771
if hasattr(self, 'model_class'):
6872
results = [self.model_class(**result)

databuilder/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from setuptools import find_packages, setup
77

8-
__version__ = '7.4.5'
8+
__version__ = '7.4.6'
99

1010
requirements_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
1111
'requirements.txt')

0 commit comments

Comments
 (0)