[ISSUE] Intermittent 403 "Failed to retrieve tenant ID for given token" with Azure service principal is reported as an SDK parsing bug and not retried
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 57/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- azure, python
- Domain
- authentication, backend-api-design
Research direction
Start by reading _base_client._is_retryable, which the issue identifies as the retry decision point, and trace how plain-text 403 responses become PermissionDenied. The report has no deterministic reproduction or debug logs, so first look for existing retry and response parsing tests covering these paths. Done when a test captures the reported transient response behavior and the resulting retry or error handling matches the intended behavior.
Written by the indexing model from the issue text.
Description
Description
We intermittently get a 403 Forbidden with a plain-text body from the Unity Catalog API when authenticating as an Azure service principal (client secret). Most requests succeed; a fraction fail on the first call made by a freshly created WorkspaceClient.
The SDK raises PermissionDenied with the message below. The response body is plain text rather than JSON, so the SDK reports "unable to parse response ... likely a bug in the Databricks SDK":
databricks.sdk.errors.platform.PermissionDenied: unable to parse response. This is likely a bug in the Databricks SDK for Python or the underlying API. Please report this issue with the following debugging information to the SDK issue tracker at https://github.com/databricks/databricks-sdk-py/issues. Request log:```GET /api/2.1/unity-catalog/tables/<catalog>.<schema>.<table>
< 403 Forbidden
< Failed to retrieve tenant ID for given token```
Two things seem worth looking at on the SDK side:
- The message is misleading. A plain-text 403 from the control plane is reported as a probable SDK bug, and as
PermissionDenied, which suggests a missing privilege. The cause looks like an intermittent failure to validate the token, not a permissions problem, because the identical request succeeds moments later in other runs. - It is not retried.
_base_client._is_retryableonly matches connection errors, timeouts,Retry-Afterresponses and a fixed list of message substrings, andFailed to retrieve tenant ID for given tokenis not in that list. The error therefore surfaces immediately. We now work around it with our own retry aroundtables.get.
Reproduction
I do not have a deterministic reproduction; it is intermittent. The pattern is:
from databricks.sdk import WorkspaceClient
w = WorkspaceClient(
host="https://<workspace>.azuredatabricks.net",
azure_tenant_id="<tenant-id>",
azure_client_id="<sp-client-id>",
azure_client_secret="<sp-client-secret>",
)
w.tables.get("<catalog>.<schema>.<table>") # occasionally fails with the 403 above
Each run is a new process that builds a new client and makes this call right away. The tenant ID is set explicitly and is correct, because the same configuration works for most runs.
Expected behavior
Either the request succeeds, or the SDK retries the transient token rejection. If it still fails, the error would ideally say the token could not be validated, not suggest an SDK bug or a missing permission.
Is it a regression?
Unknown. We upgraded from 0.139.0 to 0.156.0 around the time we first noticed it, but I cannot tell whether the errors started before that. I read the changelog for 0.140.0 to 0.162.0 and found nothing about Azure auth or error handling in that range.
Debug Logs
Not captured yet. The request log included in the exception is shown above.
Other Information
- OS: Linux (Alpine-based container)
- Python: 3.12
- Version: databricks-sdk 0.156.0
- Auth: Azure service principal with client secret (
azure_client_id,azure_client_secret,azure_tenant_id) - Observed in two different Azure Databricks workspaces, each with its own service principal and tenant configuration.
Additional context
- Similar message, different cause: terraform-provider-databricks#2723 reported the same text, but there the account ID was simply wrong, so it failed every time. Ours works most of the time with the same configuration.
- Is this a known transient condition on the Databricks side, for example shortly after a token is issued? If so, treating it as retryable in the SDK would help every Azure service principal user.
- Dominant language
- Python
- Stars
- 577
- Forks
- 229
- Avg merge
- 40m
- Merged PRs (30d)
- 12
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from databricks/databricks-sdk-py
-
Difficulty 1/5 1-3 hours Newbie friendliness 62/100
databricks/databricks-sdk-py#1602 · 2 reactions ·
Maintainers usually reply within 1 day
-
[ISSUE] Docs state serving endpoints support at most ten served entities; actual limit is 15Possibly taken @divya0709 claimed this 95 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 92/100
databricks/databricks-sdk-py#1496 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
databricks/databricks-sdk-py#1495 · 1 comment ·
Maintainers usually reply within 1 day
-
[ISSUE] `get_api_error` fails with `TypeError: object of type '_io.BufferedReader' has no len()¨`Possibly taken @mittalpk claimed this 110 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
databricks/databricks-sdk-py#1489 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
databricks/databricks-sdk-py#1451 ·
Maintainers usually reply within 1 day
All issues in databricks/databricks-sdk-py
Similar issues
-
namespace
Difficulty 1/5 Under an hour Newbie friendliness 68/100
EclipseFdn/open-vsx.org#15604 ·
Maintainers usually reply within 1 day
-
app: scripts severity: low status: backlog type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
netbox-community/netbox-scripts#164 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 5 days
-
Public function to read participants.tsvPossibly taken @bruAristimunha claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 85/100
huggingface/tau#799 ·
Maintainers usually reply within 2 days