Skip to content

Commit 6b81d8e

Browse files
jucorclaude
andcommitted
Fix CI: use find_dotenv() and fall back to DATABASE_* vars
connect_to_db() in test_postgres_real_data.py had a hardcoded .env path that doesn't work inside Docker containers, and required DATABASE_URL with no fallback. Now uses find_dotenv() to search up the directory tree, and falls back to DATABASE_HOST/PORT/NAME/USER/PASSWORD (which the docker-compose.test.yml delphi service already provides). Also removes dead POSTGRES_* env vars from the CI exec command — nothing in Delphi reads those anymore. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 464da16 commit 6b81d8e

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

.github/workflows/python-ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ jobs:
9090
-e AWS_REGION=us-east-1 \
9191
-e AWS_ACCESS_KEY_ID=dummy \
9292
-e AWS_SECRET_ACCESS_KEY=dummy \
93-
-e POSTGRES_HOST=postgres \
94-
-e POSTGRES_PASSWORD=PdwPNS2mDN73Vfbc \
95-
-e POSTGRES_DB=polis-test \
9693
delphi \
9794
bash -c " \
9895
set -e; \

delphi/tests/test_postgres_real_data.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,25 @@ def write_to_dynamodb(dynamodb_client, conversation_id, conv):
102102

103103

104104
def connect_to_db():
105-
"""Connect to PostgreSQL database using DATABASE_URL from env / .env file."""
106-
from pathlib import Path
107-
from dotenv import load_dotenv
105+
"""Connect to PostgreSQL database using DATABASE_URL or DATABASE_* env vars."""
106+
from dotenv import find_dotenv, load_dotenv
108107

109-
# Load .env from the repo root (two levels up from tests/)
110-
load_dotenv(Path(__file__).parent.parent.parent / '.env')
108+
# Walk up directories to find .env (works both locally and in containers)
109+
load_dotenv(find_dotenv())
111110

112111
database_url = os.environ.get('DATABASE_URL')
113112
if not database_url:
114-
print("DATABASE_URL environment variable is not set")
115-
return None
113+
# Fall back to individual DATABASE_* vars (same pattern as postgres.py)
114+
host = os.environ.get('DATABASE_HOST')
115+
port = os.environ.get('DATABASE_PORT', '5432')
116+
name = os.environ.get('DATABASE_NAME')
117+
user = os.environ.get('DATABASE_USER')
118+
password = os.environ.get('DATABASE_PASSWORD', '')
119+
if host and name and user:
120+
database_url = f"postgres://{user}:{password}@{host}:{port}/{name}"
121+
else:
122+
print("Neither DATABASE_URL nor DATABASE_HOST/NAME/USER are set")
123+
return None
116124

117125
try:
118126
conn = psycopg2.connect(database_url, connect_timeout=5)

0 commit comments

Comments
 (0)