Why does my nightly job crash whenever a batch comes back empty? I keep getting the same stack trace.
The job fails because the averaging step divides the running total by the number of records in the batch.
When the batch comes back empty that count is zero, and an integer division by zero is undefined — so the runtime raises instead of returning a value. The stack trace you keep seeing is pointing at that line, not at the loader above it.
Guard the denominator before you divide. For a batch held in rows, that looks like:
if rows: mean = total / len(rows) else: mean = 0.0 log.warning("empty batch, skipping")