Skip to content

Commit

Permalink
[ADD] Make sqlalchemy_extractor compatible with sqlalchemy>=1.4 (#2213)
Browse files Browse the repository at this point in the history
* [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]>
  • Loading branch information
mikekutzma authored Dec 7, 2023
1 parent eb7f45b commit 613f78a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions databuilder/databuilder/extractor/sql_alchemy_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Any

from pyhocon import ConfigFactory, ConfigTree
from sqlalchemy import create_engine
from sqlalchemy import create_engine, text

from databuilder import Scoped
from databuilder.extractor.base_extractor import Extractor
Expand Down Expand Up @@ -62,7 +62,11 @@ def _execute_query(self) -> None:
Create an iterator to execute sql.
"""
if not hasattr(self, 'results'):
self.results = self.connection.execute(self.extract_sql)
results = self.connection.execute(text(self.extract_sql))
# Makes this forward compatible with sqlalchemy >= 1.4
if hasattr(results, "mappings"):
results = results.mappings()
self.results = results

if hasattr(self, 'model_class'):
results = [self.model_class(**result)
Expand Down
2 changes: 1 addition & 1 deletion databuilder/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from setuptools import find_packages, setup

__version__ = '7.4.5'
__version__ = '7.4.6'

requirements_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'requirements.txt')
Expand Down

0 comments on commit 613f78a

Please sign in to comment.