Not quite ready to merge as-is, but close: three small fixes (roughly an hour of work) stand between this file and a safe merge tomorrow. I read `export_job.py` only; I did not run it or its tests.

The structure is good. The four functions each do one thing, the SQL is parameterised, the date window is half-open so no invoice is counted twice, and the connection is always closed.

**Fix before merging**

1. **A failed export looks like a success to cron.** `run()` catches every exception, logs one line and exits with code 0 (`export_job.py:56-57`).
   - Example: the finance endpoint returns a 503 at 02:00. The job logs "export failed", cron records success, and finance has no file for that day.
   - Because the job only ever exports "yesterday", that day is never retried.
   - Fix: use `log.exception(...)` and then `raise` (or `sys.exit(1)`), so the traceback is kept and cron alerting fires.

2. **Customer email addresses are written to the log.** Line 52 logs every `customer_email` in the export. On a day with 5,000 paid invoices, that is 5,000 addresses in a log file with its own retention and access rules. Log the count and the day only.

3. **The upload has no timeout.** `requests.post` on line 42 waits forever if the endpoint accepts the connection and then stalls. The job would hang until someone kills it, with no error logged. Add `timeout=(10, 120)` or similar.

**Worth doing, but can follow the merge**

- **No way to re-run a missed day.** The day is hard-coded to yesterday (line 47). An optional date argument lets you backfill after an outage.
- **Tests cover only the CSV header and one row.** Nothing tests an upload failure, an empty day, or `run()` itself. By your own tests-first standard, at least add a test that a failed upload produces a non-zero exit, since that is the behaviour fix 1 changes.
- **Amount formatting is inconsistent.** `amount_cents / 100` writes 1010 cents as `10.1` and 100 cents as `1.0`. If finance's importer expects two decimals, use `f"{amount_cents / 100:.2f}"`.
- **`FINANCE_UPLOAD_URL` is read at import time** (line 16). Importing the module without that variable set, as a test would, raises `KeyError`. Reading it inside `upload()` avoids that.
- **No logging setup when run as a script.** Unless something else configures logging, the "exporting" and "export finished" lines are dropped and only errors reach stderr. One `logging.basicConfig(level=logging.INFO)` under `__main__` fixes it.

**One thing to check**

"Yesterday" comes from the server's local date, and the query compares it to `paid_at`. If `paid_at` is stored with a time zone and the database session's zone differs from the server's or from finance's, invoices paid near midnight land in the wrong day's file. I can't tell from this file alone which column type and zones are in use.

VERDICT: READY WITH CHANGES
