File tree 3 files changed +14
-8
lines changed
3 files changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,10 @@ Unreleased
14
14
server stacktraces into exception messages.
15
15
- Refactoring: The module namespace ``crate.client.test_util`` has been
16
16
renamed to ``crate.testing.util``.
17
+ - Error handling: At two spots in cursor / value converter handling, where
18
+ ``assert`` statements have been used, ``ValueError`` exceptions are raised
19
+ now.
20
+
17
21
18
22
.. _Migrate from crate.client to sqlalchemy-cratedb: https://cratedb.com/docs/sqlalchemy-cratedb/migrate-from-crate-client.html
19
23
.. _sqlalchemy-cratedb: https://pypi.org/project/sqlalchemy-cratedb/
Original file line number Diff line number Diff line change @@ -222,9 +222,11 @@ def _convert_rows(self):
222
222
"""
223
223
Iterate rows, apply type converters, and generate converted rows.
224
224
"""
225
- assert ( # noqa: S101
226
- "col_types" in self ._result and self ._result ["col_types" ]
227
- ), "Unable to apply type conversion without `col_types` information"
225
+ if not ("col_types" in self ._result and self ._result ["col_types" ]):
226
+ raise ValueError (
227
+ "Unable to apply type conversion "
228
+ "without `col_types` information"
229
+ )
228
230
229
231
# Resolve `col_types` definition to converter functions. Running
230
232
# the lookup redundantly on each row loop iteration would be a
@@ -302,10 +304,10 @@ def _timezone_from_utc_offset(tz) -> timezone:
302
304
"""
303
305
UTC offset in string format (e.g. `+0530`) to `datetime.timezone`.
304
306
"""
305
- # TODO: Remove use of `assert`. Better use exceptions?
306
- assert ( # noqa: S101
307
- len ( tz ) == 5
308
- ), f"Time zone ' { tz } ' is given in invalid UTC offset format"
307
+ if len ( tz ) != 5 :
308
+ raise ValueError (
309
+ f"Time zone ' { tz } ' is given in invalid UTC offset format"
310
+ )
309
311
try :
310
312
hours = int (tz [:3 ])
311
313
minutes = int (tz [0 ] + tz [3 :])
Original file line number Diff line number Diff line change @@ -116,7 +116,7 @@ def test_create_with_timezone_as_utc_offset_failure(self):
116
116
Verify the cursor trips when trying to use invalid UTC offset strings.
117
117
"""
118
118
connection = self .get_mocked_connection ()
119
- with self .assertRaises (AssertionError ) as ex :
119
+ with self .assertRaises (ValueError ) as ex :
120
120
connection .cursor (time_zone = "foobar" )
121
121
self .assertEqual (
122
122
str (ex .exception ),
You can’t perform that action at this time.
0 commit comments