Skip to content

fix(worker): guard average-time print on compute_time list, not analytics_line_count#82

Merged
Androz2091 merged 1 commit intomainfrom
fix/empty-analytics-take-2
May 4, 2026
Merged

fix(worker): guard average-time print on compute_time list, not analytics_line_count#82
Androz2091 merged 1 commit intomainfrom
fix/empty-analytics-take-2

Conversation

@Androz2091
Copy link
Copy Markdown
Member

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:

File state line_count compute_time old result new result
Truly empty 0 [] (#81) is_partial=True, OK is_partial=True, OK
Lines, no event_type >0 [] crash is_partial=True, OK
Normal >0 >0 is_partial=False, OK is_partial=False, OK

Auto-merging since the API is broken on this case in production right now.

…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.
@Androz2091 Androz2091 merged commit f3ff71d into main May 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant