From d0f1ec2999c7894594bb890886d52c59db790364 Mon Sep 17 00:00:00 2001
From: Piotr Sarna
Date: Mon, 31 May 2021 14:26:36 +0200
Subject: [PATCH] query: fix deprecation warning for tracing
Tracing code uses a deprecated mechanism for fetching the first row
when populating traces. The behavior is now fixed.
---
cassandra/query.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/cassandra/query.py b/cassandra/query.py
index 0e7a41dc2d..f7a5b8fdf5 100644
--- a/cassandra/query.py
+++ b/cassandra/query.py
@@ -996,7 +996,8 @@ def populate(self, max_wait=2.0, wait_for_complete=True, query_cl=None):
SimpleStatement(self._SELECT_SESSIONS_FORMAT, consistency_level=query_cl), (self.trace_id,), time_spent, max_wait)
# PYTHON-730: There is race condition that the duration mutation is written before started_at the for fast queries
- is_complete = session_results and session_results[0].duration is not None and session_results[0].started_at is not None
+ session_row = session_results.one() if session_results else None
+ is_complete = session_row is not None and session_row.duration is not None and session_row.started_at is not None
if not session_results or (wait_for_complete and not is_complete):
time.sleep(self._BASE_RETRY_SLEEP * (2 ** attempt))
attempt += 1
@@ -1006,7 +1007,6 @@ def populate(self, max_wait=2.0, wait_for_complete=True, query_cl=None):
else:
log.debug("Fetching parital trace info for trace ID: %s", self.trace_id)
- session_row = session_results[0]
self.request_type = session_row.request
self.duration = timedelta(microseconds=session_row.duration) if is_complete else None
self.started_at = session_row.started_at