Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle google.api_core.exceptions.OutOfRange exception and throw IntegrityError #571

Merged
merged 1 commit into from Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion google/cloud/spanner_dbapi/cursor.py
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/spanner_dbapi/test_cursor.py
Expand Up @@ -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
Expand Down