Skip to content

Commit 5fb1edf

Browse files
Copilotmykaul
andcommitted
Refactor TruncateError handling for better readability
Keep TruncateError in the error tuple but check for it specifically within the block to avoid retry logic. This makes it clearer that TruncateError is similar to other request errors but requires different handling. Co-authored-by: mykaul <4655593+mykaul@users.noreply.github.com>
1 parent 8543c04 commit 5fb1edf

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

cassandra/cluster.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5257,21 +5257,18 @@ def _set_result(self, host, connection, pool, response):
52575257
self.query, retry_num=self._query_retries, **response.info)
52585258
elif isinstance(response, (OverloadedErrorMessage,
52595259
IsBootstrappingErrorMessage,
5260-
ServerError)):
5260+
TruncateError, ServerError)):
52615261
log.warning("Host %s error: %s.", host, response.summary)
52625262
if self._metrics is not None:
52635263
self._metrics.on_other_error()
5264+
# TruncateError should not be retried as it indicates a permanent failure
5265+
if isinstance(response, TruncateError):
5266+
self._set_final_exception(response.to_exception())
5267+
return
52645268
cl = getattr(self.message, 'consistency_level', None)
52655269
retry = retry_policy.on_request_error(
52665270
self.query, cl, error=response,
52675271
retry_num=self._query_retries)
5268-
elif isinstance(response, TruncateError):
5269-
# TruncateError should not be retried as it indicates a permanent failure
5270-
log.warning("Host %s truncate error: %s.", host, response.summary)
5271-
if self._metrics is not None:
5272-
self._metrics.on_other_error()
5273-
self._set_final_exception(response.to_exception())
5274-
return
52755272
elif isinstance(response, PreparedQueryNotFound):
52765273
if self.prepared_statement:
52775274
query_id = self.prepared_statement.query_id

0 commit comments

Comments
 (0)