fix(worker): guard average-time print on compute_time list, not analytics_line_count#82
Merged
Androz2091 merged 1 commit intomainfrom May 4, 2026
Merged
Conversation
…tics_line_count PR #81 used analytics_line_count > 0 as the divide-by-zero guard, but that variable is incremented at the top of the analytics loop — before the 'if not event_type: continue' skip. So a file whose lines all lack event_type (Discord apparently ships these for some kinds of partial exports) re-hit the same ZeroDivisionError surfaced as UNKNOWN_ERROR for package 14be73071701467d3aae144ab2e72f86. The actual condition for 'we have nothing to average' is that compute_time_per_line is empty. Guard on it directly. Behavior is identical for the two clean cases (empty file, fully-populated file) and additionally handles the lines-without-event_type case gracefully — is_partial stays True, no stats produced, no crash.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #81 — same package, still UNKNOWN_ERROR after the deploy at 08:07 UTC. New trace at 08:25 UTC, same line:
```
File "/app/tasks.py", line 438, in read_analytics_file
print(f'Average compute time per line: {sum(compute_time_per_line) / len(compute_time_per_line)}')
ZeroDivisionError: division by zero
```
#81 used `analytics_line_count > 0` as the guard, which was the wrong condition. `analytics_line_count` is incremented at the top of the loop, before the `if not 'event_type' in analytics_line_json: continue` skip. So a file whose lines all lack `event_type` (the failing package's actual shape) has `line_count > 0` but `compute_time_per_line == []` — guard misses, divide blows up.
Real condition: `if compute_time_per_line`.
Behavior:
event_typeAuto-merging since the API is broken on this case in production right now.