Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] Make sqlalchemy_extractor compatible with sqlalchemy>=1.4 #2213

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading