Skip to content

query: fix deprecation warning for tracing #1103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cassandra/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very big 👍 to moving session_row declaration higher here and using it for both the wait test and subsequent operations!

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
Expand All @@ -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
Expand Down