Skip to content

Commit 14bfe86

Browse files
authored
Add DistributedTransactionCommitFailureError (#483)
1 parent 8f94af5 commit 14bfe86

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Changelog
55
-----
66

77
- Added ``NumberOfTransactionsExceededError`` to ``sqlalchemy_hana.errors``
8+
- Added ``DistributedTransactionCommitFailureError`` to ``sqlalchemy_hana.errors``
89

910
4.1.0
1011
-----

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ maintainers = [
4646
name = "sqlalchemy-hana"
4747
readme = "README.rst"
4848
requires-python = "~=3.10"
49-
version = "4.1.0"
49+
version = "4.2.0"
5050

5151
[project.optional-dependencies]
5252
alembic = ["alembic~=1.12"]

sqlalchemy_hana/errors.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ class NumberOfTransactionsExceededError(HANAError):
100100
"""Exception raised when the number of allowed transactions is exceeded."""
101101

102102

103+
class DistributedTransactionCommitFailureError(StatementExecutionError):
104+
"""Exception raised when a distributed transaction commit fails."""
105+
106+
103107
def convert_dbapi_error(dbapi_error: DBAPIError) -> DBAPIError:
104108
"""Takes a :py:exc:`sqlalchemy.exc.DBAPIError` and returns a more specific error if possible.
105109
@@ -189,6 +193,9 @@ def convert_dbapi_error(dbapi_error: DBAPIError) -> DBAPIError:
189193
and "exceed maximum number of transactions" in error.errortext
190194
):
191195
return NumberOfTransactionsExceededError.from_dbapi_error(dbapi_error)
196+
# 149 -> ERR_TX_DIST_2PC_FAILURE
197+
if error.errorcode == 149:
198+
return DistributedTransactionCommitFailureError.from_dbapi_error(dbapi_error)
192199
return dbapi_error
193200

194201

test/test_errors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
DatabaseOutOfMemoryError,
1414
DatabaseOverloadedError,
1515
DeadlockError,
16+
DistributedTransactionCommitFailureError,
1617
InvalidObjectNameError,
1718
LockAcquisitionError,
1819
LockWaitTimeoutError,
@@ -104,6 +105,7 @@ class TestConvertDBAPIError(TestBase):
104105
"transaction error: exceed maximum number of transactions",
105106
NumberOfTransactionsExceededError,
106107
),
108+
(149, "something", DistributedTransactionCommitFailureError),
107109
],
108110
)
109111
def test_convert_dbapi_error(
@@ -128,3 +130,4 @@ def test_convert_dbapi_error_no_wrap(self, errorcode: int, errortext: str) -> No
128130
error = HdbcliError(errorcode, errortext)
129131
dbapi_error = DBAPIError(None, None, error)
130132
assert convert_dbapi_error(dbapi_error) is dbapi_error
133+
assert convert_dbapi_error(dbapi_error) is dbapi_error

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)