Skip to content

test(proxy/db): scrub DATABASE_URL across test_routing_prisma_wrapper to stop env leak - #30342

Draft
cursor[bot] wants to merge 1 commit into
litellm_internal_stagingfrom
cursor/ci-autofix-automation-0663
Draft

test(proxy/db): scrub DATABASE_URL across test_routing_prisma_wrapper to stop env leak#30342
cursor[bot] wants to merge 1 commit into
litellm_internal_stagingfrom
cursor/ci-autofix-automation-0663

Conversation

@cursor

@cursor cursor Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Relevant issues

n/a (CI autofix). Fixes the recurring proxy-infra / Run tests failure on PRs against litellm_internal_staging whose changes do not touch any DB code, e.g. PR #30333 (CLAUDE.md only) run.

Linear ticket

n/a

Pre-Submission checklist

  • I have added meaningful tests
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have requested a Greptile review

Screenshots / Proof of Fix

Reproduced the leak locally on this branch (without the fixture) and confirmed the fix.

$ env -u DATABASE_URL python3 -m pytest \
    tests/test_litellm/proxy/db/test_routing_prisma_wrapper.py \
    /tmp/leak_check.py
...
test_routing_prisma_wrapper.py::test_writer_get_rds_iam_token_uses_database_host_env_vars PASSED
test_routing_prisma_wrapper.py::test_reader_iam_refresh_uses_parsed_endpoint PASSED
leak_check.py::test_zz_database_url_must_be_unset_after_routing_tests FAILED
> AssertionError: DATABASE_URL leaked: 'postgresql://litellm:WRITER-TOKEN@writer.aurora.local:5432/litellm?schema=public'

# After applying the autouse fixture in this PR:
$ env -u DATABASE_URL python3 -m pytest \
    tests/test_litellm/proxy/db/test_routing_prisma_wrapper.py \
    /tmp/leak_check.py
...
======================== 35 passed ========================

The failing CI job before this change: https://github.com/BerriAI/litellm/actions/runs/27451742107/job/81148306753

FAILED tests/test_litellm/proxy/common_utils/test_key_rotation_e2e.py::TestDeprecatedKeyLookupDbE2E::test_deprecated_key_grace_period_cache_hit_path - httpx.ConnectError: All connection attempts failed
====== 1 failed, 3241 passed, 374 warnings, 2 rerun in 289.47s ======

Type

Test
Bug Fix

Changes

PrismaWrapper.get_rds_iam_token writes DATABASE_URL (and DATABASE_URL_READ_REPLICA) straight into os.environ. The two test_writer_get_rds_iam_token_* tests in test_routing_prisma_wrapper.py use monkeypatch.delenv("DATABASE_URL", raising=False) to clear the variable before exercising that path; but because pytest's monkeypatch.delitem only records history when the key was already present, an originally-unset DATABASE_URL is never tracked. The synthesized writer URL (postgresql://litellm:WRITER-TOKEN@writer.aurora.local:5432/litellm?schema=public) therefore survives teardown and leaks into the rest of the xdist worker.

test_key_rotation_e2e.py::TestDeprecatedKeyLookupDbE2E::test_deprecated_key_grace_period_cache_hit_path skips when DATABASE_URL is unset and tries to prisma_client.connect() otherwise. Once the leak is in place the skip check passes, the connect attempt aborts with httpx.ConnectError: All connection attempts failed, the test reruns 2x (reruns=2 on the proxy-infra workflow) and the whole job fails. That is what shipped on every recent staging-targeted PR whose diff did not touch any DB code (e.g. #30333).

Add an autouse snapshot/restore fixture for the managed DATABASE_* env vars at the top of test_routing_prisma_wrapper.py. This mirrors the existing _scrub_db_env fixture in test_db_url_settings.py, whose docstring already calls out exactly this monkeypatch limitation. No production code changes; the fix is contained to the leaking test module.

Open in Web View Automation 

…stop env leak

PrismaWrapper.get_rds_iam_token writes DATABASE_URL directly into
os.environ. monkeypatch.delenv tracks nothing when the variable was
unset to begin with, so the synthesized writer URL (e.g. postgresql://
litellm:WRITER-TOKEN@writer.aurora.local:5432/litellm) survives the
test and leaks across the xdist worker.

Downstream effect: tests/test_litellm/proxy/common_utils/
test_key_rotation_e2e.py::TestDeprecatedKeyLookupDbE2E::
test_deprecated_key_grace_period_cache_hit_path stops skipping
(os.getenv("DATABASE_URL") is now truthy) and tries to open a real
Prisma connection against the bogus host, failing with
httpx.ConnectError under proxy-infra CI.

Add an autouse snapshot/restore fixture for the managed DATABASE_*
env vars, mirroring the pattern already used in test_db_url_settings.py
where the same docstring already documents that monkeypatch cannot
undo direct os.environ mutations.

Co-authored-by: Krrish Dholakia <krrish-berri-2@users.noreply.github.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants