Try to fix #365.

This commit is contained in:
Friedrich Lindenberg 2021-04-22 18:51:20 +02:00
parent 45794d349f
commit c13b79fc59

View File

@ -19,29 +19,30 @@ def convert_row(row_type, row):
def iter_result_proxy(rp, step=None): def iter_result_proxy(rp, step=None):
"""Iterate over the ResultProxy.""" """Iterate over the ResultProxy."""
try: while True:
while True: if step is None:
if step is None: chunk = rp.fetchall()
chunk = rp.fetchall() else:
else: chunk = rp.fetchmany(size=step)
chunk = rp.fetchmany(size=step) if not chunk:
if not chunk: break
break for row in chunk:
for row in chunk: yield row
yield row
except ResourceClosedError:
return
class ResultIter(object): class ResultIter(object):
""" SQLAlchemy ResultProxies are not iterable to get a """SQLAlchemy ResultProxies are not iterable to get a
list of dictionaries. This is to wrap them. """ list of dictionaries. This is to wrap them."""
def __init__(self, result_proxy, row_type=row_type, step=None): def __init__(self, result_proxy, row_type=row_type, step=None):
self.row_type = row_type self.row_type = row_type
self.result_proxy = result_proxy self.result_proxy = result_proxy
self.keys = list(result_proxy.keys()) try:
self._iter = iter_result_proxy(result_proxy, step=step) 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): def __next__(self):
try: try: