From 602d52f41655d235ec78fcec9ae1add464a91b49 Mon Sep 17 00:00:00 2001 From: Friedrich Lindenberg Date: Thu, 16 Dec 2021 10:21:40 +0100 Subject: [PATCH] Try to make convert row work on sqla 1.3 and 1.4. --- dataset/util.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/dataset/util.py b/dataset/util.py index a9b5093..4fa225d 100644 --- a/dataset/util.py +++ b/dataset/util.py @@ -6,17 +6,29 @@ from sqlalchemy.exc import ResourceClosedError QUERY_STEP = 1000 row_type = OrderedDict +try: + # SQLAlchemy > 1.4.0, new row model. + from sqlalchemy.engine import Row # noqa + + def convert_row(row_type, row): + if row is None: + return None + return row_type(row._mapping.items()) + + +except ImportError: + # SQLAlchemy < 1.4.0, no _mapping. + + def convert_row(row_type, row): + if row is None: + return None + return row_type(row.items()) + class DatasetException(Exception): pass -def convert_row(row_type, row): - if row is None: - return None - return row_type(row._mapping.items()) - - def iter_result_proxy(rp, step=None): """Iterate over the ResultProxy.""" while True: