:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(exchange-rate): handle missing historical.csv in CSV loader (#62315)
posthog[bot]90a2c1b92313
diff --git a/posthog/models/exchange_rate/sql.py b/posthog/models/exchange_rate/sql.pyindex d678f9b371ba..72884087b677 100644--- a/posthog/models/exchange_rate/sql.py+++ b/posthog/models/exchange_rate/sql.py@@ -40,7 +40,19 @@ def HISTORICAL_EXCHANGE_RATE_DICTIONARY():currencies = []# Load the CSV file- with open(os.path.join(os.path.dirname(__file__), "historical.csv")) as f:+ csv_path = os.path.join(os.path.dirname(__file__), "historical.csv")+ if not os.path.exists(csv_path):+ # `historical.csv` is a large (~9MB) git-tracked asset that ships with the repo.+ # When it's missing the checkout is incomplete (e.g. a partial/sparse clone or a+ # sandboxed environment that skipped large files), not a logic bug — so surface an+ # actionable message instead of a bare FileNotFoundError from `open` below.+ raise FileNotFoundError(+ f"Exchange rate data file not found at {csv_path}. "+ "This file is tracked in git and required to backfill ClickHouse exchange rates; "+ "ensure your checkout includes it (a partial or sparse clone may have skipped it)."+ )++ with open(csv_path) as f:reader = csv.reader(f)# Get header row with currency codesdiff --git a/posthog/models/exchange_rate/test/test_sql.py b/posthog/models/exchange_rate/test/test_sql.pynew file mode 100644index 000000000000..be84c2148008--- /dev/null+++ b/posthog/models/exchange_rate/test/test_sql.py@@ -0,0 +1,23 @@+import os++import pytest++from posthog.models.exchange_rate.sql import HISTORICAL_EXCHANGE_RATE_DICTIONARY+++def test_historical_dictionary_loads_real_data():+ rates_dict = HISTORICAL_EXCHANGE_RATE_DICTIONARY()++ assert rates_dict+ assert "2024-12-31" in rates_dict+ assert rates_dict["2024-12-31"]["EUR"] > 0+++def test_historical_dictionary_raises_actionable_error_when_csv_missing(monkeypatch):+ def missing(path):+ return False++ monkeypatch.setattr(os.path, "exists", missing)++ with pytest.raises(FileNotFoundError, match="Exchange rate data file not found"):+ HISTORICAL_EXCHANGE_RATE_DICTIONARY()