Fix two places that can cause issues under SQLite

In both places, we may potentially iterate over a result set after
closing the read transaction.

Change-Id: I0afce854287a4375c525c19c49ed0ec01bac76b1
This commit is contained in:
Dmitry Tantsur
2023-09-07 17:03:39 +02:00
parent 985c7fdf21
commit 7b9007375e

View File

@@ -387,7 +387,7 @@ def _paginate_query(model, limit=None, marker=None, sort_key=None,
return []
if return_base_tuple:
# The caller expects a tuple, lets just give it to them.
return res
return [tuple(r) for r in res]
# Everything is a tuple in a resultset from the unified interface
# but for objects, our model expects just object access,
# so we extract and return them.
@@ -585,16 +585,9 @@ class Connection(api.Connection):
# If we are not using sorting, or any other query magic,
# we could likely just do a query execution and
# prepare the tuple responses.
results = _paginate_query(models.Node, limit, marker,
sort_key, sort_dir, query,
return_base_tuple=True)
# Need to copy the data to close out the _paginate_query
# object.
new_result = [tuple([ent for ent in r]) for r in results]
# Explicitly free results so we don't hang on to it.
del results
return new_result
return _paginate_query(models.Node, limit, marker,
sort_key, sort_dir, query,
return_base_tuple=True)
def get_node_list(self, filters=None, limit=None, marker=None,
sort_key=None, sort_dir=None, fields=None):
@@ -1481,7 +1474,8 @@ class Connection(api.Connection):
result = session.query(
field
).filter(models.Conductor.online.is_(False))
return [row[0] for row in result]
result = [row[0] for row in result]
return result
def get_online_conductors(self):
with _session_for_read() as session: