Deadlock in mutually exclusive account_id and zone_id resolution raises erroneous ValueError
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Cerca nella codebase _get_account_id_path_param, _get_zone_id_path_param e il pattern account_id/zone_id mutuamente esclusivo; inizia con zero_trust.access.applications.list. Riproduci la chiamata con il solo account_id descritta nell’issue, quindi verifica che le requests con esattamente un parametro non generino più il ValueError relativo al parametro mancante, mentre la fornitura di entrambi continui a generare l’errore di mutua esclusione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Confirm this is a Python library issue and not an underlying Cloudflare API issue.
- This is an issue with the Python library
Describe the bug
In multiple classes, there is logic that attempts to extract an account_id or zone_id from the base client object if they are not provided as arguments. The code then verifies that exactly one of these parameters is present.
The current implementation looks like this:
if account_id is None:
account_id = self._client._get_account_id_path_param()
if zone_id is None:
zone_id = self._client._get_zone_id_path_param()
if account_id and zone_id:
raise ValueError("You cannot provide both account_id and zone_id")
The Bug
Both _get_account_id_path_param() and _get_zone_id_path_param() actively raise a ValueError if the client does not possess the requested parameter. This inadvertently creates a deadlock:
- If you only provide one parameter (as required), the attempt to fetch the missing second parameter from the client throws a ValueError.
- To bypass the first two if statements without throwing an error, you would have to provide both parameters (either via arguments or the client). However, doing so triggers the third if statement, throwing a
ValueErrorfor providing both.
Expected Behavior
The method should execute successfully, recognizing that exactly one mutually exclusive parameter (account_id or zone_id) was provided.
Actual Behavior
A ValueError is incorrectly raised no matter what combination of account_id or zone_id is provided.
Proposed Solution
There are two straightforward ways to resolve this deadlock:
- Wrap the parameter retrievals in a try...except block that catches and suppresses the
ValueErrors. - Modify the
_get_*_path_param()methods so they returnNoneinstead of throwing an exception when a parameter is missing.
To Reproduce
I personally encountered this issue using client.zero_trust.access.applications.list(account_id=account_id), but a quick search indicates this pattern appears in roughly 180 occurrences across the codebase.
- Initalize the Cloudflare client with an API key
- Retrieve the target account ID via searching or just first available, e.g.
account_id = next(tier(client.accounts.list())).id - Attempt to fetch the applications list using only the
account_id:applications = client.zero_trust.access.applications.list(account_id=account_id) ValueErrorincorrectly raised:Missing zone_id argument; Please provide it at the client level, e.g. Cloudflare(zone_id='abcd') or per method.
Code snippets
OS
macOS 15.7.4
Python version
3.13.11
Library version
5.0.0b2
- Lingua principale
- Python
- Stelle
- 509
- Fork
- 150
- Merge medio
- 3h 15m
- PR unite (30g)
- 1
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di cloudflare/cloudflare-python
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
cloudflare/cloudflare-python#2747 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
cloudflare/cloudflare-python#2718 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
cloudflare/cloudflare-python#2692 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
cloudflare/cloudflare-python#2679 · 4 commenti · 5 reazioni ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
cloudflare/cloudflare-python#2745 · 1 commento ·
Tutte le issue di cloudflare/cloudflare-python
Issue simili
-
area: harness bug status: needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Human-Agent-Society/reef#625 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 80/100
learningequality/kolibri#15351 · 2 commenti ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Name consistency Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
eellak/triplestore#65 · 1 commento ·