From 613f78a9d1aa7905060ae7ada5e4fd08349cceb4 Mon Sep 17 00:00:00 2001 From: Mike Kutzma Date: Thu, 7 Dec 2023 16:37:33 -0500 Subject: [PATCH] [ADD] Make sqlalchemy_extractor compatible with sqlalchemy>=1.4 (#2213) * [ADD] Make sqlalchemy_extractor compatible with sqlalchemy>=1.4 Signed-off-by: mikekutzma * Chore: Bump databuilder version to 7.4.6 Signed-off-by: Mike Kutzma --------- Signed-off-by: mikekutzma Signed-off-by: Mike Kutzma --- .../databuilder/extractor/sql_alchemy_extractor.py | 8 ++++++-- databuilder/setup.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/databuilder/databuilder/extractor/sql_alchemy_extractor.py b/databuilder/databuilder/extractor/sql_alchemy_extractor.py index db7e384880..dfdec3935a 100644 --- a/databuilder/databuilder/extractor/sql_alchemy_extractor.py +++ b/databuilder/databuilder/extractor/sql_alchemy_extractor.py @@ -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 @@ -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) diff --git a/databuilder/setup.py b/databuilder/setup.py index 6333cf0959..0e1604b5b2 100644 --- a/databuilder/setup.py +++ b/databuilder/setup.py @@ -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')