Skip to content

fix: honor environment overrides when copying clients - #57

Open
omerbek wants to merge 1 commit into
coingecko:mainfrom
omerbek:fix/copy-environment-base-url
Open

omerbek wants to merge 1 commit into
coingecko:mainfrom
omerbek:fix/copy-environment-base-url

Conversation

@omerbek

@omerbek omerbek commented Nov 8, 2026 •

Copy link
Copy Markdown

Problem

Coingecko.copy() and AsyncCoingecko.copy() always pass the original base_url to the constructor, even when environment is explicitly overridden. Since an explicit URL takes precedence over environment selection, client.with_options(environment="demo") created from a Pro client continues sending requests to pro-api.coingecko.com. The reverse switch has the same problem.

Change

Only inherit the original URL when no environment override is supplied. An explicitly supplied base_url still wins, and ordinary copies preserve their current URL. Apply the same behavior to both clients; add Pro→Demo, Demo→Pro, and explicit-custom-URL precedence regressions plus a README example.

This is an independent finding, not work taken from an existing issue. Searches for environment, with_options, base_url, and copy did not identify a matching issue/PR; #34 is an unrelated response-model issue. CONTRIBUTING.md explicitly describes how manual generated-file patches persist across regeneration; no generator files were invented or changed here.

Verification

Windows / supported Python 3.11.5, httpx 0.28.1, pydantic 2.12.5:

  • Added regressions before the fix: 4 failed / 2 passed.
  • Copy-focused tests after the fix: 16 passed / 2 skipped.
  • Standalone sync/async smoke called the public simple.price.get() resource through httpx.MockTransport; observed request hosts switched to api.coingecko.com and pro-api.coingecko.com respectively while the original clients retained their URL. No live API request or real key was used.
  • Ruff check passed; Ruff formatter applied to the test file.
  • Full tests/test_client.py: 149 passed / 2 skipped / 2 failed. The failures are the untouched sync/async proxy-environment tests (len(client._mounts) == 1, observed 0). On Windows environment names are case-insensitive; these tests set HTTPS_PROXY and subsequently delete https_proxy. No test suppression/change is included, and I did not establish a clean baseline.

The pinned Rye development Python is 3.9.18. The full lock could not install under 3.11 because its backports-asyncio-runner==1.2.0 requires Python <3.11; I used a supported 3.11 venv with the test-tool versions above instead. The Prism-backed resource suite and pinned-3.9 development environment were not run.

AI-assisted implementation and investigation; the regression failures, offline SDK smoke, and verification results above were exercised locally.

Upstream CI approval gate

The upstream workflow API now reports three runs as completed / action_required, rather than a test result: CI, Release Doctor, and Trunk sync lock. This is an external-contributor workflow approval gate (author association NONE); no successful CI is claimed. A maintainer with repository write permissions needs to approve the permitted fork workflows. No empty commit, duplicate PR, or workflow bypass was added.

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.

1 participant