Skip to content

Commit ed60db0

Browse files
committed
stopping wrapping of driver exceptions as is maintenance issue
1 parent 790b502 commit ed60db0

File tree

4 files changed

+26
-48
lines changed

4 files changed

+26
-48
lines changed

tests/unit/test_auth_failures.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ async def test_auth_failure_during_operation(self):
121121
---------------
122122
1. Unauthorized error during query
123123
2. Permission failures on tables
124-
3. Wrapped in QueryError
125-
4. Original Unauthorized accessible
124+
3. Passed through directly
125+
4. Native exception handling
126126
127127
Why this matters:
128128
----------------
@@ -131,7 +131,7 @@ async def test_auth_failure_during_operation(self):
131131
- Role changes after connection
132132
- Fine-grained access control
133133
134-
Applications need to:
134+
Applications need direct access to:
135135
- Handle permission errors gracefully
136136
- Potentially retry with different user
137137
- Log security violations
@@ -232,7 +232,7 @@ async def test_authorization_failure_different_operations(self):
232232
1. Different permission types (SELECT, MODIFY, CREATE, etc.)
233233
2. Each permission failure handled correctly
234234
3. Error messages indicate specific permission
235-
4. Consistent wrapping in QueryError
235+
4. Exceptions passed through directly
236236
237237
Why this matters:
238238
----------------

tests/unit/test_connection_pool_exhaustion.py

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ async def test_pool_exhaustion_under_load(self, mock_session):
111111
---------------
112112
1. Pool has finite connection limit
113113
2. Excess queries fail with NoConnectionsAvailable
114-
3. Failures are wrapped in QueryError
114+
3. Exceptions passed through directly
115115
4. Success/failure count matches pool size
116116
117117
Why this matters:
@@ -121,8 +121,8 @@ async def test_pool_exhaustion_under_load(self, mock_session):
121121
- Database has connection limits
122122
- Pool size must be tuned
123123
124-
Applications must handle pool exhaustion
125-
gracefully with retries or backoff.
124+
Applications need direct access to
125+
handle pool exhaustion with retries.
126126
"""
127127
async_session = AsyncCassandraSession(mock_session)
128128

@@ -152,14 +152,8 @@ def execute_async_side_effect(*args, **kwargs):
152152

153153
# First pool_size queries should succeed
154154
successful = [r for r in results if not isinstance(r, Exception)]
155-
# NoConnectionsAvailable is wrapped in QueryError
156-
from async_cassandra.exceptions import QueryError
157-
158-
failed = [
159-
r
160-
for r in results
161-
if isinstance(r, QueryError) and isinstance(r.cause, NoConnectionsAvailable)
162-
]
155+
# NoConnectionsAvailable is now passed through directly
156+
failed = [r for r in results if isinstance(r, NoConnectionsAvailable)]
163157

164158
assert len(successful) == pool_size
165159
assert len(failed) == 3
@@ -240,12 +234,9 @@ def execute_async_side_effect(*args, **kwargs):
240234
mock_session.execute_async.side_effect = execute_async_side_effect
241235

242236
# First attempts fail
243-
from async_cassandra.exceptions import QueryError
244-
245237
for i in range(3):
246-
with pytest.raises(QueryError) as exc_info:
238+
with pytest.raises(NoConnectionsAvailable):
247239
await async_session.execute("SELECT * FROM test")
248-
assert isinstance(exc_info.value.cause, NoConnectionsAvailable)
249240

250241
# Wait a bit (simulating pool recovery)
251242
await asyncio.sleep(0.1)
@@ -301,7 +292,7 @@ def execute_async_side_effect(*args, **kwargs):
301292
try:
302293
result = await async_session.execute(f"SELECT {i}")
303294
results.append(result)
304-
except Exception: # QueryError wrapping NoConnectionsAvailable
295+
except NoConnectionsAvailable: # NoConnectionsAvailable is now passed through directly
305296
results.append(None)
306297

307298
# Should have 1 failure (3rd query)
@@ -381,14 +372,8 @@ def execute_async_side_effect(*args, **kwargs):
381372
results = await asyncio.gather(*tasks, return_exceptions=True)
382373

383374
# Should have mix of successes and failures
384-
from async_cassandra.exceptions import QueryError
385-
386375
successes = sum(1 for r in results if not isinstance(r, Exception))
387-
failures = sum(
388-
1
389-
for r in results
390-
if isinstance(r, QueryError) and isinstance(r.cause, NoConnectionsAvailable)
391-
)
376+
failures = sum(1 for r in results if isinstance(r, NoConnectionsAvailable))
392377

393378
assert successes >= max_concurrent
394379
assert failures > 0
@@ -629,11 +614,8 @@ def execute_async_side_effect(*args, **kwargs):
629614
degradation_active = True
630615

631616
# Non-critical query should fail
632-
from async_cassandra.exceptions import QueryError
633-
634-
with pytest.raises(QueryError) as exc_info:
617+
with pytest.raises(NoConnectionsAvailable):
635618
await async_session.execute("SELECT * FROM test")
636-
assert isinstance(exc_info.value.cause, NoConnectionsAvailable)
637619

638620
# Critical query should still work
639621
result = await async_session.execute("CRITICAL: SELECT * FROM system.local")

tests/unit/test_network_failures.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
from cassandra.cluster import ConnectionException, Host, NoHostAvailable
3333

3434
from async_cassandra import AsyncCassandraSession, AsyncCluster
35-
from async_cassandra.exceptions import QueryError
3635

3736

3837
class TestNetworkFailures:
@@ -107,8 +106,8 @@ async def test_partial_network_failure(self, mock_session):
107106
---------------
108107
1. Connection established but queries fail
109108
2. ConnectionException during execution
110-
3. Wrapped in QueryError for context
111-
4. Original exception preserved
109+
3. Exception passed through directly
110+
4. Native error handling preserved
112111
113112
Why this matters:
114113
----------------
@@ -117,8 +116,8 @@ async def test_partial_network_failure(self, mock_session):
117116
- Network degradation after connect
118117
- Load balancer issues
119118
120-
Applications need to detect and handle
121-
these "connected but broken" states.
119+
Applications need direct access to
120+
handle these "connected but broken" states.
122121
"""
123122
async_session = AsyncCassandraSession(mock_session)
124123

@@ -127,12 +126,11 @@ async def test_partial_network_failure(self, mock_session):
127126
ConnectionException("Connection closed by remote host")
128127
)
129128

130-
# ConnectionException is wrapped in QueryError
131-
with pytest.raises(QueryError) as exc_info:
129+
# ConnectionException is now passed through directly
130+
with pytest.raises(ConnectionException) as exc_info:
132131
await async_session.execute("SELECT * FROM test")
133132

134133
assert "Connection closed by remote host" in str(exc_info.value)
135-
assert isinstance(exc_info.value.cause, ConnectionException)
136134

137135
@pytest.mark.asyncio
138136
async def test_connection_timeout_during_query(self, mock_session):
@@ -323,9 +321,8 @@ def execute_async_side_effect(*args, **kwargs):
323321
try:
324322
result = await async_session.execute(f"SELECT {i}")
325323
results.append(result.rows[0]["flap_count"])
326-
except QueryError as e:
327-
if isinstance(e.cause, ConnectionException):
328-
errors.append(str(e))
324+
except ConnectionException as e:
325+
errors.append(str(e))
329326

330327
# Should have mix of successes and failures
331328
assert len(results) == 3 # Even numbered attempts succeed

tests/unit/test_protocol_edge_cases.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from cassandra.connection import ProtocolError
3333

3434
from async_cassandra import AsyncCassandraSession
35-
from async_cassandra.exceptions import ConnectionError, QueryError
35+
from async_cassandra.exceptions import ConnectionError
3636

3737

3838
class TestProtocolEdgeCases:
@@ -298,7 +298,7 @@ async def test_protocol_error_recovery(self, mock_session):
298298
---------------
299299
1. Protocol errors can be transient
300300
2. Recovery possible after errors
301-
3. Multiple attempts tracked
301+
3. Direct exception handling
302302
4. Eventually succeeds
303303
304304
Why this matters:
@@ -308,8 +308,8 @@ async def test_protocol_error_recovery(self, mock_session):
308308
- Temporary corruption
309309
- Race conditions
310310
311-
Retry with new connection often
312-
resolves transient issues.
311+
Users can implement retry logic
312+
with new connections as needed.
313313
"""
314314
async_session = AsyncCassandraSession(mock_session)
315315

@@ -331,9 +331,8 @@ def execute_async_side_effect(*args, **kwargs):
331331

332332
# First two attempts should fail
333333
for i in range(2):
334-
with pytest.raises(QueryError) as exc_info:
334+
with pytest.raises(ProtocolError):
335335
await async_session.execute("SELECT * FROM test")
336-
assert isinstance(exc_info.value.__cause__, ProtocolError)
337336

338337
# Third attempt should succeed
339338
result = await async_session.execute("SELECT * FROM test")

0 commit comments

Comments
 (0)