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: