It isn't ready to merge as written, but the structure is good and the fixes are small enough to finish before tomorrow. The job is split into clear steps (query, write, upload, run), the SQL is parameterised, and both the file and the connection are closed properly. The two problems that block the merge: the job can fail without anyone finding out, and it writes every customer's email address to the logs each night.

Also, the docstring says the job is tested by `test_export_job.py`, but that file isn't in this directory, so I couldn't look at the tests.

## Blocking

**1. A failed export looks like a success (`export_job.py:56-57`).** `except Exception` logs the error and then `run()` returns normally, so the process exits with code 0. For example, if the finance endpoint returns a 500, `raise_for_status()` raises, one line goes to the log, cron records success, and finance gets no file for that day. Nothing alerts anyone. `log.error("%s", error)` also drops the stack trace.
*Fix:* use `log.exception(...)` and then `raise`, or `sys.exit(1)`, so cron or your monitoring sees the failure.

**2. Customer emails are written to the logs every night (`export_job.py:52`).** `[row[1] for row in rows]` is the full list of customer emails. Logs are usually kept longer and seen by more people than the database, which makes this a PII and compliance problem.
*Fix:* log only the count and the day.

**3. The tests are missing or too thin.** The test file isn't here, and the docstring says it only covers "CSV header and one row." Nothing tests the paths that matter most: a failed upload exits non-zero, a day with no invoices, how amounts are formatted, or which day counts as "yesterday."

## High

**4. Amounts assume every currency has 2 decimal places (`export_job.py:37`).** `amount_cents / 100` treats every currency as having cents. For example, ¥500 is stored as `500`, so it exports as `5.0` when it should be `500`. Currencies with 3 decimal places (KWD, BHD) come out wrong as well. Floats also drop trailing zeros: `2000` exports as `20.0` instead of `20.00`, which can break finance's import.
*Fix:* use `Decimal` with a table of decimal places per currency, and format to a fixed number of decimals.

**5. No timeout on the upload (`export_job.py:42`).** If the endpoint stops responding, `requests.post` can wait forever, and the next night's run then starts while this one is still going.
*Fix:* add `timeout=(10, 60)` or similar.

**6. "Yesterday" depends on the server's timezone (`export_job.py:47`, `:28`).** `date.today()` uses the server's local time. A plain date compared against `paid_at` is read in the database session's timezone. If those differ from each other, or from the timezone finance means by "yesterday," invoices near midnight end up in the wrong day's file or in none.
*Fix:* choose one timezone explicitly (UTC or finance's) and pass timezone-aware datetimes as the query bounds.

## Medium

**7. You can't re-run a missed day.** The day is fixed to "yesterday." After an outage, the only way to backfill is to edit the code. Add an optional `--date` argument.

**8. Logging is never configured.** Nothing calls `logging.basicConfig` under `__main__`, so the `log.info` lines (`:52`, `:55`) are silently dropped. Only warnings and errors reach stderr, so you won't see "export finished" either.

**9. Reading an environment variable at import time (`export_job.py:16`).** `os.environ["FINANCE_UPLOAD_URL"]` raises `KeyError` as soon as the module is imported, so the tests have to set it first. Read it inside `run()` or `upload()` instead.

**10. CSV files containing customer emails pile up in `/var/exports`.** They're never deleted, they get default file permissions, and the job doesn't create the directory if it's missing. Either delete the file after a successful upload or tighten its permissions and add a retention policy.

## Low / minor

**11. Spreadsheet formula injection.** Email addresses can legally contain `=`, `+` or `@`. If finance opens the CSV in Excel, a value that starts with one of these can be run as a formula. Prefix those cells with `'`.

**12. The connection step isn't covered by the error handling.** `psycopg2.connect` (`:49`) sits outside the `try`. That happens to give a non-zero exit, but once #1 is fixed the error handling should be consistent.

**13. The CSV is written in place.** A crash halfway through leaves a partial file behind. That's harmless today because the upload comes after the write, but it matters if anything else reads the directory.

**14. Days with no invoices upload a header-only file.** That's probably intended, but confirm finance expects it.

**15. `fetchall()` loads every row into memory.** That's fine at nightly volumes; it only matters if the volume grows a lot.

**16. No type hints or function docstrings.** This is cosmetic.

Fixing #1–#3 plus #5 is a few hours' work, and the job would be safe to merge after that. #4 and #6 should go in before it handles real multi-currency or cross-timezone data.

VERDICT: NOT READY
