diff --git a/google/cloud/spanner_dbapi/cursor.py b/google/cloud/spanner_dbapi/cursor.py index 36b28af712..3aea48ef4c 100644 --- a/google/cloud/spanner_dbapi/cursor.py +++ b/google/cloud/spanner_dbapi/cursor.py @@ -14,6 +14,9 @@ """Database cursor for Google Cloud Spanner DB-API.""" +import warnings +from collections import namedtuple + import sqlparse from google.api_core.exceptions import Aborted @@ -23,8 +26,6 @@ from google.api_core.exceptions import InvalidArgument from google.api_core.exceptions import OutOfRange -from collections import namedtuple - from google.cloud import spanner_v1 as spanner from google.cloud.spanner_dbapi.checksum import ResultsChecksum from google.cloud.spanner_dbapi.exceptions import IntegrityError @@ -120,10 +121,12 @@ def rowcount(self): :raises: :class:`NotImplemented`. """ - raise NotImplementedError( + warnings.warn( "The `rowcount` property is non-operational. Request " "resulting rows are streamed by the `fetch*()` methods " - "and can't be counted before they are all streamed." + "and can't be counted before they are all streamed.", + UserWarning, + stacklevel=2, ) def _raise_if_closed(self): diff --git a/tests/unit/spanner_dbapi/test_cursor.py b/tests/unit/spanner_dbapi/test_cursor.py index c340c4e5ce..f2c9130613 100644 --- a/tests/unit/spanner_dbapi/test_cursor.py +++ b/tests/unit/spanner_dbapi/test_cursor.py @@ -61,11 +61,19 @@ def test_property_description(self): self.assertIsNotNone(cursor.description) self.assertIsInstance(cursor.description[0], ColumnInfo) - def test_property_rowcount(self): + @mock.patch("warnings.warn") + def test_property_rowcount(self, warn_mock): connection = self._make_connection(self.INSTANCE, self.DATABASE) cursor = self._make_one(connection) - with self.assertRaises(NotImplementedError): - cursor.rowcount + + cursor.rowcount + warn_mock.assert_called_once_with( + "The `rowcount` property is non-operational. Request " + "resulting rows are streamed by the `fetch*()` methods " + "and can't be counted before they are all streamed.", + UserWarning, + stacklevel=2, + ) def test_callproc(self): from google.cloud.spanner_dbapi.exceptions import InterfaceError