Skip to content
Open
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
30 changes: 20 additions & 10 deletions apps/worker/services/test_analytics/ta_process_flakes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from collections import defaultdict
from datetime import timedelta

import sentry_sdk
Expand Down Expand Up @@ -33,13 +34,12 @@ def fetch_current_flakes(repo_id: int) -> dict[bytes, Flake]:
}


def get_testruns(upload: ReportSession) -> QuerySet[Testrun]:
upload_filter = Q(upload_id=upload.id)

def get_testruns_for_uploads(upload_ids: list[int]) -> QuerySet[Testrun]:
# we won't process flakes for testruns older than 1 day
return Testrun.objects.filter(
Q(timestamp__gte=timezone.now() - timedelta(days=1)) & upload_filter
).order_by("timestamp")
Q(timestamp__gte=timezone.now() - timedelta(days=1))
& Q(upload_id__in=upload_ids)
).order_by("upload_id", "timestamp")


def handle_pass(curr_flakes: dict[bytes, Flake], test_id: bytes):
Expand Down Expand Up @@ -81,10 +81,11 @@ def handle_failure(

@sentry_sdk.trace
def process_single_upload(
upload: ReportSession, curr_flakes: dict[bytes, Flake], repo_id: int
upload_id: int,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unused upload_id parameter in process_single_upload

Low Severity

The upload_id parameter added to process_single_upload is never referenced anywhere in the function body. It's passed in from process_flakes_for_commit at the call site but serves no purpose inside the function, making it dead code that may confuse future readers about its intended use.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 834f4ba. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Bug: The upload_id parameter in the process_single_upload function is unused and can be removed.
Severity: LOW

Suggested Fix

Remove the upload_id parameter from the function definition of process_single_upload at line 84 and update the corresponding call site at lines 132-134 to no longer pass this argument.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: apps/worker/services/test_analytics/ta_process_flakes.py#L84

Potential issue: The function `process_single_upload` is defined with a parameter
`upload_id`. However, this parameter is not used anywhere within the function's body.
The value is passed correctly from the call site, but since it is not utilized, it
serves no functional purpose. This is a result of a refactoring that decoupled testrun
retrieval from processing, leaving the parameter as a vestige. While it does not cause
any runtime errors or incorrect behavior, it represents dead code that can be confusing
for future maintenance.

Did we get this right? 👍 / 👎 to inform future reviews.

testruns: list[Testrun],
curr_flakes: dict[bytes, Flake],
repo_id: int,
):
testruns = get_testruns(upload)

for testrun in testruns:
test_id = bytes(testrun.test_id)
match testrun.outcome:
Expand All @@ -106,7 +107,7 @@ def process_flakes_for_commit(repo_id: int, commit_id: str):
log.info(
"process_flakes_for_commit: starting processing",
)
uploads = get_relevant_uploads(repo_id, commit_id)
uploads = list(get_relevant_uploads(repo_id, commit_id))

log.info(
"process_flakes_for_commit: fetched uploads",
Expand All @@ -120,8 +121,17 @@ def process_flakes_for_commit(repo_id: int, commit_id: str):
extra={"flakes": [flake.test_id.hex() for flake in curr_flakes.values()]},
)

upload_ids = [upload.id for upload in uploads]
all_testruns = get_testruns_for_uploads(upload_ids)

testruns_by_upload: dict[int, list[Testrun]] = defaultdict(list)
for testrun in all_testruns:
testruns_by_upload[testrun.upload_id].append(testrun)

for upload in uploads:
process_single_upload(upload, curr_flakes, repo_id)
process_single_upload(
upload.id, testruns_by_upload[upload.id], curr_flakes, repo_id
)
log.info(
"process_flakes_for_commit: processed upload",
extra={"upload": upload.id},
Expand Down
Loading