From 716bc8a9d828c205237497ccc1b52d28b213e052 Mon Sep 17 00:00:00 2001 From: David Evans Date: Mon, 4 Sep 2023 08:33:28 +0100 Subject: [PATCH] Prevent error when closing an unused cursor SQLAlchemy will attempt to close cursor objects even if, for whatever reason, they haven't actually been used and therefore have no associated query to cancel. --- trino/dbapi.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/trino/dbapi.py b/trino/dbapi.py index 62ce893b..47130dab 100644 --- a/trino/dbapi.py +++ b/trino/dbapi.py @@ -706,7 +706,8 @@ def cancel(self): self._query.cancel() def close(self): - self.cancel() + if self._query is not None: + self.cancel() # TODO: Cancel not only the last query executed on this cursor # but also any other outstanding queries executed through this cursor.