databricks / databricks-sdk-go

Databricks SDK for Go
https://docs.databricks.com/dev-tools/sdk-go.html
Apache License 2.0
51 stars 42 forks source link

[ISSUE] Bug in the Databricks SDK for Go or the underlying REST API #959

Open hb0313 opened 4 months ago

hb0313 commented 4 months ago

I have devops piepline setup to deploy bundle on Dev and QA env, both have different job. However, QA shows below error but the deployment is successful. Not sure what the issue is? But looks like after deployment the cmd try to login to dev through QA job.

Error: unexpected error handling request: json: cannot unmarshal number into Go struct field APIErrorBody.error_code of type string. This is likely a bug in the Databricks SDK for Go or the underlying REST API. Please report this issue with the following debugging information to the SDK issue tracker at https://github.com/databricks/databricks-sdk-go/issues. Request log:

GET /api/2.0/preview/scim/v2/Me

  • Host:
  • Accept: application/json
  • Authorization: REDACTED
  • Traceparent: 00-d3cb700e1fc3e0fc18794ffbadefe1ab-XXXXXXXXXXXXXXXX
  • User-Agent: cli/0.221.1 databricks-sdk-go/0.42.0 go/1.21.10 os/windows cmd/bundle_validate auth/pat cicd/azure-devops < HTTP/2.0 403 Forbidden < Content-Length: 70 < Content-Type: application/json; charset=utf-8 < Date: Thu, 27 Jun 2024 19:27:31 GMT < Server: databricks < Vary: Accept-Encoding < X-Databricks-Reason-Phrase: Invalid access to Org: 33XXXXXXXXXX.XX < { < "error_code": 403, < "message": "Invalid access to Org: 33XXXXXXXXXX.XX" < }

Devops pipeline yml

trigger:
 branches:
   include:
     - main 

pool:
  vmImage: 'windows-latest'

stages: 
- stage: DeployDev
  displayName: 'Deploy to Development'

  jobs:
    - job: Dev
      variables:
      - group: Databricks DAB Dev
      steps: 
        - checkout: self
        - script: 
            choco install databricks-cli
        - script : |
            databricks bundle validate
            databricks bundle deploy -t dev
          env:
            DATABRICKS_TOKEN: $(token-dev)

    - job: QA
      variables:
      - group: Databricks DAB Dev
      steps: 
        - checkout: self
        - script: 
            choco install databricks-cli
        - script : |
            databricks bundle validate
            databricks bundle deploy -t qa
          env:
            DATABRICKS_TOKEN: $(token-qa)

Let me know if any addition info is required.

joe-koch-kard commented 1 day ago

What worked for me was, instead of setting a DATABRICKS_TOKEN, setting a DATABRICKS_CLIENT_ID and DATABRICKS_CLIENT_SECRET generated for the service principal. E.g.

env:
  DATABRICKS_TOKEN: ${{ secrets.STAGING_WORKSPACE_TOKEN }}

becomes

env:
  DATABRICKS_CLIENT_SECRET: ${{ secrets.DATABRICKS_CLIENT_SECRET }} 
  DATABRICKS_CLIENT_ID: ${{ secrets.DATABRICKS_CLIENT_ID }}

Here's how I generated the secret, you do have to be an admin.

Used databricks/setup-cli@v0.232.1.