**It isn't ready to merge tomorrow.** The biggest problem is that failures are silent: if the upload or the database query fails, the job writes one log line and exits as if it succeeded, so cron sees success and finance just doesn't get a file. Second, it writes every customer's email address into the logs every night. Third, the test file the docstring cites isn't in this folder. None of these takes long to fix.

## Must fix before merge

1. **Failures look like success** (`export_job.py:56-57`). `run()` catches every exception, logs it, and returns normally, so the process exits with code 0.
   - Example: the finance endpoint returns HTTP 500. `raise_for_status()` raises, the job logs `export failed: 500 Server Error`, and it exits 0. Cron and any monitoring treat the run as successful, and nobody hears about it until finance asks where the file is.
   - Expected: a non-zero exit, or an alert.
   - Fix: log with `log.exception(...)` (which also keeps the stack trace that `log.error` currently drops), then re-raise. Keep the `finally: conn.close()`.

2. **Customer emails go into the logs** (`export_job.py:52`). `[row[1] for row in rows]` puts every paying customer's email into an info-level log line every night. That is personal data in log storage, which usually has wider access and longer retention than the database. Log only the count and the day.

3. **The test file is missing.** The docstring says the job is covered by `test_export_job.py`, but that file isn't in this directory. If it lives somewhere else, fine. If not, there are no tests. Either way, a test of the CSV header plus one row doesn't cover the parts most likely to break. Minimum test plan:
   - the date range passed to the query for a given day
   - an upload failure makes `run()` raise
   - the amount formatting described below
   - a day with no invoices

## Should fix (small changes)

4. **No upload timeout** (`export_job.py:42`). `requests.post` has no `timeout`, so a hung endpoint blocks the job indefinitely, and the next night's run can overlap it. Add something like `timeout=60`.

5. **Amounts are wrong for some currencies, and inconsistently formatted** (`export_job.py:37`).
   - `amount_cents / 100` assumes every currency has 2 decimal places. A ¥1000 invoice stored as `1000` exports as `10.0`.
   - The division also gives floats, so `1000` USD exports as `10.0` rather than `10.00`, which tends to trip up finance imports.
   - Fix: format with `Decimal`, using each currency's number of decimal places. Or, if you only ever bill in 2-decimal currencies, add a comment saying so and format as `f"{amount_cents / 100:.2f}"`.

6. **Unclear which timezone defines "yesterday"** (`export_job.py:47`, `:28`). `date.today()` uses the server's local timezone, and the date bounds are compared against `paid_at` in the database session's timezone. If those two differ from what finance means by "yesterday" (often UTC), invoices paid near midnight end up in the wrong day's file or in none. Decide the timezone explicitly and test both boundaries.

7. **No way to re-run a missed day.** The day is fixed to "yesterday", so if a night fails you can't export it again later. Let `run(day=None)` accept a date, from the command line or an environment variable.

## Minor

- `UPLOAD_URL = os.environ[...]` runs at import time, so just importing the module (including from tests) fails with a `KeyError` if the variable isn't set. Read it inside `upload()` or `run()`.
- The CSV files in `/var/exports` contain customer emails, are created with default permissions, and are never deleted. Decide on file permissions and a retention period.

The overall structure is good: fetch, write, and upload are small, separate functions, and the SQL is parameterised. Items 1–3 are about an hour of work including tests. With those done, I'd call it "ready with changes", and items 4–7 could follow in a later change.

VERDICT: NOT READY
