I don't think `export_job.py` should merge tomorrow as it stands. The biggest problem: when the job fails, it logs an error and exits successfully, so cron never notices and finance just doesn't get a file. Two more block the merge: it writes every customer's email address into the logs, and the test file named in its docstring isn't in the directory. None of the fixes is large; together they're roughly half a day of work.

## Blocking (fix before merge)

**1. Failures are silent: High.** Lines 56–57 catch every exception, log it and return normally, so the process exits with code 0.
- *Example:* the finance endpoint returns a 503. `raise_for_status()` raises, the error is logged, and the job exits 0. Cron and any monitoring record a successful run, and finance gets no file for that day with no alert.
- *Expected:* a non-zero exit code. Log with `log.exception(...)` and then re-raise, or call `sys.exit(1)`. Using `log.exception` also keeps the traceback, which `log.error("%s", error)` throws away.

**2. Customer emails are written to the logs: High.** Line 52 logs `[row[1] for row in rows]`, which is the full list of customer emails, every night. That puts personal data in your log storage, which usually has wider access and longer retention than the database. Log the count only, or the invoice IDs if you need them.

**3. The tests aren't here: High.** The docstring says the job is "Tested by test_export_job.py (CSV header and one row)", but that file isn't in this directory. If it lives somewhere else, those two cases still leave most of the job untested. I'd want tests for at least:
- the upload fails, so the job must exit non-zero;
- the query returns no rows, so the file should contain just the header (or the job should skip the upload, whichever you decide);
- amount formatting, including a currency with no minor units (see item 4);
- the date window, i.e. which invoices count as "yesterday".

Line 16 makes testing harder than it needs to be. It reads `FINANCE_UPLOAD_URL` when the module is imported, so the module can't even be imported in a test unless that variable is set. Reading it inside `run()` fixes that.

**4. Amounts are floats and assume two decimal places: High if you export more than one currency.** Line 37 divides by 100 and writes a Python float.
- *Example:* an invoice of 500 JPY (yen has no minor unit, so `amount_cents` = 500) is exported as `5.0`. It should be `500`.
- Even for USD, 1000 cents comes out as `10.0`, not `10.00`, which finance tooling may reject or misread.
- *Fix:* use `Decimal`, with each currency's number of decimal places, and format to a fixed precision. If you only ever bill in two-decimal currencies, this drops to Medium. Still fix the formatting, and say in the code that you're assuming two decimals.

## Should fix (could follow in a quick next PR if you must)

**5. The "yesterday" window depends on the server's time zone: Medium.** Line 47 takes `date.today()` in the server's local time. The query then compares a plain date against `paid_at`, so Postgres converts it to midnight in the database session's time zone. If those two time zones differ from each other, or from the business day finance expects, invoices paid near midnight end up on the wrong day's file or on no file at all. Pick UTC (or the business time zone) explicitly and pass full timestamps.

**6. The upload has no timeout: Medium.** `requests.post` on line 42 has no timeout, so a hung endpoint blocks the job forever. Add something like `timeout=60`, and consider a retry.

**7. A missed day can't be re-run: Medium.** The date is hard-coded to "yesterday", so if the 02:00 run fails you can't re-export that day. Take an optional `--date` argument.

**8. CSV files with personal data pile up: Low to Medium.** Every night a file of customer emails is written to `/var/exports` and never deleted. Either decide on a retention period, or write to a temp file and delete it after a successful upload.

**9. The file write isn't atomic: Low.** If the job crashes mid-write, a partial file is left at the final path. Write to `path + ".tmp"` and rename it once it's complete.

**10. The info logs go nowhere: Low.** `__main__` never configures logging, and Python's default level is WARNING, so both `log.info` lines are dropped. Only errors would show. Add `logging.basicConfig(level=logging.INFO)`.

## Open question

The upload request on line 42 doesn't send any credentials. If the finance endpoint expects a token, this will fail once it's deployed. If the endpoint is protected some other way, such as network rules or credentials built into the URL, ignore this.

Items 1–4 are the merge blockers. Each is a small change, and adding the tests in item 3 will also show that the fixes for 1 and 4 work.

VERDICT: NOT READY
