From c13b79fc596cd570e243376cbd42bea63fbae4eb Mon Sep 17 00:00:00 2001 From: Friedrich Lindenberg Date: Thu, 22 Apr 2021 18:51:20 +0200 Subject: [PATCH] Try to fix #365. --- dataset/util.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/dataset/util.py b/dataset/util.py index 2842f8a..49512f4 100644 --- a/dataset/util.py +++ b/dataset/util.py @@ -19,29 +19,30 @@ def convert_row(row_type, row): def iter_result_proxy(rp, step=None): """Iterate over the ResultProxy.""" - try: - while True: - if step is None: - chunk = rp.fetchall() - else: - chunk = rp.fetchmany(size=step) - if not chunk: - break - for row in chunk: - yield row - except ResourceClosedError: - return + while True: + if step is None: + chunk = rp.fetchall() + else: + chunk = rp.fetchmany(size=step) + if not chunk: + break + for row in chunk: + yield row class ResultIter(object): - """ SQLAlchemy ResultProxies are not iterable to get a - list of dictionaries. This is to wrap them. """ + """SQLAlchemy ResultProxies are not iterable to get a + list of dictionaries. This is to wrap them.""" def __init__(self, result_proxy, row_type=row_type, step=None): self.row_type = row_type self.result_proxy = result_proxy - self.keys = list(result_proxy.keys()) - self._iter = iter_result_proxy(result_proxy, step=step) + try: + self.keys = list(result_proxy.keys()) + self._iter = iter_result_proxy(result_proxy, step=step) + except ResourceClosedError: + self.keys = [] + self._iter = iter([]) def __next__(self): try: