Skip to content

Commit 5e3e57a

Browse files
committed
Validate that dbapi2.Error propagates the underlying cdb2.Error
Signed-off-by: Michael Thorpe <michael@thorpe.dev>
1 parent 1a792fc commit 5e3e57a

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/build
2+
/comdb2.egg-info/
23
/dist
34
/python_comdb2.egg-info
45
*.pyc

tests/test_dbapi2.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
DataError,
2929
Datetime,
3030
DatetimeUs,
31-
Error,
3231
ForeignKeyConstraintError,
3332
IntegrityError,
3433
InterfaceError,
@@ -793,6 +792,21 @@ def raise_not_supported_error():
793792
conn.commit()
794793

795794

795+
@patch("comdb2.cdb2.Handle")
796+
def test_error_wraps_underlying(handle):
797+
handle.return_value.execute.side_effect = partial(throw_on, "begin")
798+
799+
conn = connect("mattdb", "dev")
800+
cursor = conn.cursor()
801+
802+
with pytest.raises(OperationalError) as exc_info:
803+
cursor.execute("insert into simple(key, val) values(1, 2)")
804+
805+
assert isinstance(exc_info.value.__cause__, cdb2.Error)
806+
underlying = exc_info.value.__cause__
807+
assert underlying.error_code == 42
808+
809+
796810
def test_autocommit_handles():
797811
conn = connect("mattdb", "dev", autocommit=True)
798812
cursor = conn.cursor()
@@ -936,8 +950,7 @@ def test_unsupported_column_decode_exception():
936950
cursor.fetchall()
937951

938952
errmsg = (
939-
"Failed to decode CDB2_INTERVALDS column 0 ('delta'):"
940-
" Unsupported column type"
953+
"Failed to decode CDB2_INTERVALDS column 0 ('delta'): Unsupported column type"
941954
)
942955
assert errmsg in str(exc_info.value)
943956

0 commit comments

Comments
 (0)