fix: read SAFE_TRANSACTION_SERVICE_API_KEY when api_key is not provided - #2766
Amine E. (aelmanaa) wants to merge 1 commit into
Conversation
`TransactionServiceApi` read the environment variable as a default argument, so it was evaluated once at import time, and `from_ethereum_client` always passed `api_key=None` explicitly, which dropped it entirely. Read the variable when the instance is created if no api key is provided. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
❌ ErrorsYour PR has failed checks. Please review the issues below and take necessary action before merging. 🚦 1 Pipeline job failed
Useful? React with 👍 / 👎 This comment will be updated automatically if new data arrives.🔗 Commit SHA: d1c3ccd | Docs | View more details | Give us feedback! |
|
Before signing: the CLA link in the bot comment and in CONTRIBUTING (https://safe.global/cla) currently returns 404 (also |
Fixes #2764
TransactionServiceApi.__init__readSAFE_TRANSACTION_SERVICE_API_KEYas a default argument, so it was evaluated once at import time, andSafeBaseAPI.from_ethereum_clientalways passesapi_key=None, which dropped it entirely. This makesapi_keydefault toNoneand reads the variable when the instance is created if no key is given, so both the constructor andfrom_ethereum_clientpick it up. An explicitly passedapi_keystill wins, and the signature is unchanged for callers.Tests:
TestTransactionServiceApiKeycovers the key from the environment (constructor andfrom_ethereum_client, including theAuthorizationheader), an explicit key overriding the environment, and no key. It runs without a Transaction Service API key or network, unlikeTestTransactionServiceAPI, which skips whenSAFE_TRANSACTION_SERVICE_API_KEYis unset.Verification (Python 3.13,
docker compose up -d db ganache):test_api_key_from_environmentfails onmain(AssertionError: None != 'env-api-key') and passes with this change; all three new tests pass.key-set-before-import Bearer key-set-before-importandkey-set-after-import.pytest -m "not network": 519 passed, 0 failed.pre-commit run --all-filespasses.This was written with Claude Code; I reviewed and tested it.