[FIX] Prevent exception if the query doesn't return rows

This commit is contained in:
David Virebayre
2023-10-09 09:27:27 +02:00
committed by Daniel Reis
parent 7972942f34
commit 464cd59da3

View File

@@ -38,5 +38,7 @@ class BaseExternalDbsource(models.Model):
cur = connection.execute(sqlquery, sqlparams)
if metadata:
cols = list(cur.keys())
rows = [r for r in cur]
# If the query doesn't return rows, trying to get them anyway
# will raise an exception `sqlalchemy.exc.ResourceClosedError`
rows = [r for r in cur] if cur.returns_rows else []
return rows, cols