`export_job.py` is not ready to merge as written: a failed export exits successfully, so finance can miss a day with nobody alerted. The structure is clean and the query is parameterised, and the four blockers are small fixes.

I reviewed by reading only; nothing was run. `test_export_job.py` is not in this directory, so what I say about tests rests on the docstring ("CSV header and one row").

## Blockers

1. **Failures are swallowed and the job exits 0** (`export_job.py:56-57`).
   - Case: the finance endpoint returns 503 at 02:00. Cron sees success, nothing retries, and that day's invoices never reach finance. Expected: non-zero exit.
   - `log.error("%s", error)` also drops the traceback.
   - Fix: use `log.exception(...)` and re-raise, or `sys.exit(1)`.

2. **No way to re-run a missed day** (`:47`).
   - The date is hard-coded to yesterday. If the 14 Nov run fails, running on 16 Nov exports only 15 Nov.
   - Fix: accept an optional date argument that defaults to yesterday.

3. **Customer emails are written to the log** (`:52`).
   - Every run logs the full list of `customer_email` values. This is personal data in log files, which usually have wider access and longer retention than the database.
   - Fix: log the count only.

4. **The upload has no timeout** (`:42`).
   - If the endpoint accepts the connection and stalls, the job hangs indefinitely with the DB connection open, and the next night's run stacks on top of it.
   - Fix: `timeout=(10, 120)` or similar.

## Should fix before or soon after merge

5. **Tests cover only the CSV writer.** There are none for the date window in `fetch_invoices`, an upload failure, the exit code from `run()`, or a day with zero invoices. Items 1, 2 and 4 each need one.

6. **"Yesterday" depends on the server and DB time zones** (`:28`, `:47`).
   - `date.today()` uses the server's local time, and the DB turns the date into a timestamp using its session time zone.
   - Case: if `paid_at` is `timestamptz` and the session is UTC while finance works in Pacific time, an invoice paid at 17:30 Pacific on 13 Nov lands in the 14 Nov file.
   - `paid_at.isoformat()` also prints no offset if the column is naive.
   - Fix: pick the time zone explicitly and build both boundaries in it.

7. **Amount formatting** (`:37`).
   - `amount_cents / 100` writes 1000 as `10.0`, not `10.00`.
   - It also assumes every currency has two decimals: 5000 JPY would be exported as `50.0`. This only matters if you bill in such currencies.
   - Fix: format with `Decimal` and a per-currency exponent, or export the raw cents and say so in the header.

8. **Re-runs upload the same file again.** Once item 2 exists, check whether the finance endpoint de-duplicates by filename or invoice id; otherwise a re-run double-posts.

9. **Export files are never cleaned up** (`:15`, `:33`). They contain emails and amounts, pile up in `/var/exports`, and get default permissions (commonly world-readable). Set mode `0600` and delete after upload or after a retention period.

10. **Possible secret in the error log.** `raise_for_status()` includes the full URL in its message. If `FINANCE_UPLOAD_URL` carries a token in the query string, it ends up in the log on every failure. No auth header is sent, so I suspect the URL is the credential; please confirm.

## Minor

11. **No logging configuration.** When run from cron, the `log.info` lines (`:52`, `:55`) go nowhere; only the error reaches stderr. Add `logging.basicConfig(level=logging.INFO)` under `__main__`.
12. **`UPLOAD_URL` is read at import time** (`:16`). Importing the module without the variable set raises `KeyError`, which makes testing awkward. `DATABASE_URL` is read inside `run()`; do the same for both.
13. **`psycopg2.connect` sits outside the `try`** (`:49`). A connection failure crashes with a traceback while every other failure is logged quietly. This resolves itself once item 1 is fixed.
14. **No encoding on `open()`** (`:33`). A non-ASCII email address can raise `UnicodeEncodeError` under a non-UTF-8 cron locale. Pass `encoding="utf-8"`.
15. **Spreadsheet formula injection.** An email starting with `=`, `+`, `-` or `@` is run as a formula if finance opens the CSV in Excel. Prefix such cells with `'`.
16. **A null `amount_cents` aborts the whole export** with a `TypeError` (`:37`). This is only possible if the column is nullable.
17. **`fetchall()` loads the whole day into memory** (`:29`). Fine at current volumes.
18. **No guard against overlapping runs.** Low risk once the timeout from item 4 is in.
19. **Zero-invoice days upload a header-only file.** Probably fine, but confirm finance expects it.

VERDICT: NOT READY
