Skip to content

Commit 698260e

Browse files
Ilya Gurovvi3k6i5
Ilya Gurov
andauthored
fix: Django and SQLAlchemy APIs are failing to use rowcount (#654)
* fix: Django and SQLAlchemy APIs are failing to use rowcount * lint fix Co-authored-by: Vikash Singh <[email protected]>
1 parent d142f19 commit 698260e

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

google/cloud/spanner_dbapi/cursor.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
"""Database cursor for Google Cloud Spanner DB API."""
1616

17-
import warnings
1817
from collections import namedtuple
1918

2019
import sqlparse
@@ -137,15 +136,11 @@ def description(self):
137136
def rowcount(self):
138137
"""The number of rows produced by the last `execute()` call.
139138
140-
:raises: :class:`NotImplemented`.
139+
The property is non-operational and always returns -1. Request
140+
resulting rows are streamed by the `fetch*()` methods and
141+
can't be counted before they are all streamed.
141142
"""
142-
warnings.warn(
143-
"The `rowcount` property is non-operational. Request "
144-
"resulting rows are streamed by the `fetch*()` methods "
145-
"and can't be counted before they are all streamed.",
146-
UserWarning,
147-
stacklevel=2,
148-
)
143+
return -1
149144

150145
@check_not_closed
151146
def callproc(self, procname, args=None):

tests/unit/spanner_dbapi/test_cursor.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,11 @@ def test_property_description(self):
6161
self.assertIsNotNone(cursor.description)
6262
self.assertIsInstance(cursor.description[0], ColumnInfo)
6363

64-
@mock.patch("warnings.warn")
65-
def test_property_rowcount(self, warn_mock):
64+
def test_property_rowcount(self):
6665
connection = self._make_connection(self.INSTANCE, self.DATABASE)
6766
cursor = self._make_one(connection)
6867

69-
cursor.rowcount
70-
warn_mock.assert_called_once_with(
71-
"The `rowcount` property is non-operational. Request "
72-
"resulting rows are streamed by the `fetch*()` methods "
73-
"and can't be counted before they are all streamed.",
74-
UserWarning,
75-
stacklevel=2,
76-
)
68+
assert cursor.rowcount == -1
7769

7870
def test_callproc(self):
7971
from google.cloud.spanner_dbapi.exceptions import InterfaceError

0 commit comments

Comments
 (0)