Skip to content
Permalink
Browse files
fix: don't try to close closed cursors (#498)
  • Loading branch information
betodealmeida committed Jan 29, 2021
1 parent d5735ea commit bf44e7b67d2de41c13053a4550484b9ea049db3e
Showing with 18 additions and 1 deletion.
  1. +2 −1 google/cloud/bigquery/dbapi/connection.py
  2. +16 −0 tests/unit/test_dbapi_connection.py
@@ -76,7 +76,8 @@ def close(self):
self._bqstorage_client._transport.grpc_channel.close()

for cursor_ in self._cursors_created:
cursor_.close()
if not cursor_._closed:
cursor_.close()

def commit(self):
"""No-op, but for consistency raise an error if connection is closed."""
@@ -176,6 +176,22 @@ def test_close_closes_all_created_cursors(self):
self.assertTrue(cursor_1._closed)
self.assertTrue(cursor_2._closed)

def test_close_closes_only_open_created_cursors(self):
connection = self._make_one(client=self._mock_client())
cursor_1 = connection.cursor()
cursor_2 = connection.cursor()
self.assertFalse(cursor_1._closed)
self.assertFalse(cursor_2._closed)

cursor_1.close()
self.assertTrue(cursor_1._closed)
cursor_1.close = mock.MagicMock()

connection.close()

self.assertFalse(cursor_1.close.called)
self.assertTrue(cursor_2._closed)

def test_does_not_keep_cursor_instances_alive(self):
from google.cloud.bigquery.dbapi import Cursor

0 comments on commit bf44e7b

Please sign in to comment.