Skip to content
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/
  2. +7 −0 tests/unit/spanner_dbapi/
@@ -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._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):

with mock.patch(
with self.assertRaises(IntegrityError):

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

0 comments on commit dffcf13

Please sign in to comment.