Deadlock in mutually exclusive account_id and zone_id resolution raises erroneous ValueError
まだ誰も着手していません。
評価
調査の方向性
コードベースで _get_account_id_path_param、_get_zone_id_path_param、および相互排他的な account_id/zone_id パターンを検索し、zero_trust.access.applications.list から始めます。issue に記載された account_id のみを指定する呼び出しを再現し、その後、パラメーターをちょうど 1 つ指定した requests では欠落パラメーターの ValueError が発生しなくなり、両方を指定した場合は引き続き相互排他エラーが発生することを確認します。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- Python
- スター
- 509
- フォーク
- 150
- 平均マージ
- 3時間 15分
- マージ済み PR(30日)
- 1
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
cloudflare/cloudflare-python のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
cloudflare/cloudflare-python#2747 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
cloudflare/cloudflare-python#2718 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
cloudflare/cloudflare-python#2692 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
cloudflare/cloudflare-python#2679 · コメント 4 件 · リアクション 5 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
cloudflare/cloudflare-python#2745 · コメント 1 件 ·
cloudflare/cloudflare-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100