Skip to content

Fix cluster_api_url("mainnet") raising AttributeError - #707

Merged
michaelhly merged 1 commit into
michaelhly:masterfrom
Amadeus-22:fix/cluster-api-url-mainnet
Oct 12, 2026
Merged

michaelhly merged 1 commit into
michaelhly:masterfrom
Amadeus-22:fix/cluster-api-url-mainnet

Conversation

@Amadeus-22

Copy link
Copy Markdown
Contributor

Problem

Since 0.40.2, cluster_api_url("mainnet") fails:

>>> from solana.utils.cluster import cluster_api_url
>>> cluster_api_url("mainnet")
AttributeError: 'ClusterUrls' object has no attribute 'mainnet'

#699 renamed the cluster literal to "mainnet", but the function still resolves the URL with getattr(urls, cluster), and the ClusterUrls field is still mainnet_beta. "mainnet" is the only value the type allows for that cluster, so there is no way to get the mainnet URL from this helper.

Change

cluster_api_url maps "mainnet" to the mainnet_beta field. I left ClusterUrls as it is so the public model does not change; renaming the field would be the alternative if you prefer it, and I can switch to that.

Tests

tests/unit/test_cluster_api_url.py only covered devnet. It now also checks testnet, and a new test_mainnet covers "mainnet" with and without TLS. test_mainnet fails on master with the error above and passes with the change.

pytest tests/unit passes (137 tests); ruff format --check, ruff check and mypy are clean on the touched files. Added a Fixed entry under Unreleased in the changelog.

🤖 Generated with Claude Code

The cluster was renamed from mainnet-beta to mainnet in michaelhly#699, but
cluster_api_url still looked the URL up by the cluster name, and the
ClusterUrls field is mainnet_beta. Every call with "mainnet" failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.31%. Comparing base (fa1f4c9) to head (ff0c6df).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #707   +/-   ##
=======================================
  Coverage   95.30%   95.31%           
=======================================
  Files          25       25           
  Lines        1917     1919    +2     
=======================================
+ Hits         1827     1829    +2     
  Misses         90       90           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@michaelhly
michaelhly merged commit e3fd25e into michaelhly:master Oct 12, 2026
9 checks passed
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