Skip to content

Commit

Permalink
[ADD] Make sqlalchemy_extractor compatible with sqlalchemy>=1.4
Browse files Browse the repository at this point in the history
Signed-off-by: mikekutzma <[email protected]>
  • Loading branch information
mikekutzma committed Nov 14, 2023
1 parent 60c268d commit ff3d59a
Showing 1 changed file with 6 additions and 2 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

0 comments on commit ff3d59a

Please sign in to comment.