**It's not ready to merge tomorrow as written.** Two problems need fixing first: when the export fails, cron is told it succeeded, and every customer email gets written to the logs. The test file the docstring mentions also isn't here. Each fix is small, so with focused work this could still go in tomorrow.

I only read the code; nothing was run. `test_export_job.py` doesn't exist in `/Users/USERNAME/Downloads/order-service-designs/p`, so I couldn't check what it covers.

## Must fix before merge

**1. Failures look like success (high)** — `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 500, or the database is down at 02:00.
- **What happens:** one log line, exit 0, cron reports success, and finance gets no file. Nobody is told.
- **What should happen:** the process exits non-zero so cron or monitoring raises an alert.
- **Fix:** use `log.exception(...)` then `raise`, or `sys.exit(1)` in `__main__`.

**2. Customer emails written to logs (high)** — `export_job.py:52`
`[row[1] for row in rows]` logs every customer email address every night. That puts personal data into log storage, which usually has wider access and longer retention than the database. Log only the count.

**3. Tests missing or too thin (high)** — docstring, `export_job.py:3`
The docstring cites `test_export_job.py`, which isn't in this directory. Even if it lives somewhere else, "CSV header and one row" leaves the parts most likely to break untested:
- upload failure makes the job exit non-zero (this would have caught #1)
- a day with no invoices
- amount formatting (see #5)
- the date window passed to the query

Mocking `requests.post` and passing a fake connection to `fetch_invoices` keeps these tests fast.

## Should fix (soon if not now)

**4. Upload has no timeout (medium)** — `export_job.py:42`
`requests.post` with no `timeout` can hang forever if the endpoint stalls. The next night's run then starts alongside the stuck one. Add something like `timeout=60`.

**5. Amounts are floats and ignore currency (medium)** — `export_job.py:37`
- **Example 1:** `amount_cents=1000` exports as `10.0`, not `10.00`.
- **Example 2:** JPY has no minor unit. If ¥500 is stored as `500`, it exports as `5.0`.
- **Fix:** format with `Decimal(amount_cents) / 100` quantized to the currency's number of decimal places. Or, simpler, export `amount_cents` as an integer and let finance convert it. Confirm with finance which format they expect.

**6. Possible timezone mismatch in the date window (medium, needs checking)** — `export_job.py:28, 47`
`date.today()` uses the server's local timezone. If `paid_at` is a `timestamptz`, Postgres reads the date as midnight in the database session's timezone. If the two differ (say, server in IST and DB session in UTC), the export window shifts by hours, and invoices near midnight can be skipped or exported twice. Using explicit UTC datetimes for both bounds removes the ambiguity.

## Minor

**7. Import fails without the upload URL** — `export_job.py:16`
`UPLOAD_URL` is read from the environment when the module is imported, so importing it in a test without `FINANCE_UPLOAD_URL` set raises `KeyError`. Read it inside `upload()` or `run()`.

**8. No way to re-run a specific day** — `export_job.py:47`
If a night fails, re-exporting that date means changing code. An optional date argument (`run(day=None)` plus a CLI flag) fixes this, and also makes #3 easier to test.

**9. CSV files with customer data are never cleaned up** — `export_job.py:48`
Files with customer emails pile up in `/var/exports` with no retention policy, and a failed upload leaves a partial file behind. Delete files after a successful upload, or agree on a retention period.

**Question for you:** on a day with no paid invoices, the job uploads a file with only the header row. Is that what finance wants?

**Shortest path to merging tomorrow:** fix #1, #2 and #4 (a few lines each) and add the failure-path and empty-day tests. If the rest has to wait, open tickets for #5–#9 so the debt is tracked. #5 and #6 affect the numbers finance receives, so check them with finance before the first production run.

VERDICT: NOT READY
