Skip to content
Permalink
Browse files
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 <3116482+vi3k6i5@users.noreply.github.com>
  • Loading branch information
Ilya Gurov and vi3k6i5 committed Jan 6, 2022
1 parent d142f19 commit 698260e4597badd38e5ad77dda43506a016826d8
Showing with 6 additions and 19 deletions.
  1. +4 −9 google/cloud/spanner_dbapi/cursor.py
  2. +2 −10 tests/unit/spanner_dbapi/test_cursor.py
@@ -14,7 +14,6 @@

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

import warnings
from collections import namedtuple

import sqlparse
@@ -137,15 +136,11 @@ def description(self):
def rowcount(self):
"""The number of rows produced by the last `execute()` call.
:raises: :class:`NotImplemented`.
The property is non-operational and always returns -1. Request
resulting rows are streamed by the `fetch*()` methods and
can't be counted before they are all streamed.
"""
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.",
UserWarning,
stacklevel=2,
)
return -1

@check_not_closed
def callproc(self, procname, args=None):
@@ -61,19 +61,11 @@ def test_property_description(self):
self.assertIsNotNone(cursor.description)
self.assertIsInstance(cursor.description[0], ColumnInfo)

@mock.patch("warnings.warn")
def test_property_rowcount(self, warn_mock):
def test_property_rowcount(self):
connection = self._make_connection(self.INSTANCE, self.DATABASE)
cursor = self._make_one(connection)

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,
)
assert cursor.rowcount == -1

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

0 comments on commit 698260e

Please sign in to comment.