Skip to content
Permalink
Browse files
fix: handle google.api_core.exceptions.OutOfRange exception and throw…
… InegrityError as expected by dbapi standards (#571)
  • Loading branch information
vi3k6i5 committed Sep 14, 2021
1 parent 1a0a435 commit dffcf13d10a0cfb6b61231ae907367563f8eed87
Showing with 9 additions and 1 deletion.
  1. +2 −1 google/cloud/spanner_dbapi/cursor.py
  2. +7 −0 tests/unit/spanner_dbapi/test_cursor.py
@@ -21,6 +21,7 @@
from google.api_core.exceptions import FailedPrecondition
from google.api_core.exceptions import InternalServerError
from google.api_core.exceptions import InvalidArgument
from google.api_core.exceptions import OutOfRange

from collections import namedtuple

@@ -241,7 +242,7 @@ def execute(self, sql, args=None):
self.connection.database.run_in_transaction(
self._do_execute_update, sql, args or None
)
except (AlreadyExists, FailedPrecondition) as e:
except (AlreadyExists, FailedPrecondition, OutOfRange) as e:
raise IntegrityError(e.details if hasattr(e, "details") else e)
except InvalidArgument as e:
raise ProgrammingError(e.details if hasattr(e, "details") else e)
@@ -251,6 +251,13 @@ def test_execute_integrity_error(self):
with self.assertRaises(IntegrityError):
cursor.execute(sql="sql")

with mock.patch(
"google.cloud.spanner_dbapi.parse_utils.classify_stmt",
side_effect=exceptions.OutOfRange("message"),
):
with self.assertRaises(IntegrityError):
cursor.execute("sql")

def test_execute_invalid_argument(self):
from google.api_core import exceptions
from google.cloud.spanner_dbapi.exceptions import ProgrammingError

0 comments on commit dffcf13

Please sign in to comment.