From 77f6a285bef72fcd64daeb87201091666aeaa31f Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Mon, 10 Mar 2025 08:05:15 +0000 Subject: [PATCH] Fixed "can't evaluate field Name in type interface{}" for `databricks queries list` (#2451) ## Changes Fixes #1888 ## Why `databricks queries list` is using override to define a template to display a list in a nice table form. This Go template was referencing to non existing anymore fields and hence failing. ## Tests Added acceptance test --- NEXT_CHANGELOG.md | 1 + acceptance/cmd/workspace/queries/output.txt | 5 ++ acceptance/cmd/workspace/queries/script | 1 + acceptance/cmd/workspace/queries/test.toml | 58 +++++++++++++++++++++ cmd/workspace/queries/overrides.go | 2 +- 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 acceptance/cmd/workspace/queries/output.txt create mode 100644 acceptance/cmd/workspace/queries/script create mode 100644 acceptance/cmd/workspace/queries/test.toml diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index 00ff7ec5e..d04de4989 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -3,6 +3,7 @@ ## Release v0.243.1 ### CLI +* Fixed "can't evaluate field Name in type interface{}" for "databricks queries list" command ([#2451](https://github.com/databricks/cli/pull/2451)) ### Bundles diff --git a/acceptance/cmd/workspace/queries/output.txt b/acceptance/cmd/workspace/queries/output.txt new file mode 100644 index 000000000..20b6395e6 --- /dev/null +++ b/acceptance/cmd/workspace/queries/output.txt @@ -0,0 +1,5 @@ + +>>> [CLI] queries list +ID Name Author +[UUID] Example query 1 user@acme.com +[UUID] Example query 2 user@acme.com diff --git a/acceptance/cmd/workspace/queries/script b/acceptance/cmd/workspace/queries/script new file mode 100644 index 000000000..476fa2153 --- /dev/null +++ b/acceptance/cmd/workspace/queries/script @@ -0,0 +1 @@ +trace $CLI queries list diff --git a/acceptance/cmd/workspace/queries/test.toml b/acceptance/cmd/workspace/queries/test.toml new file mode 100644 index 000000000..f4942283b --- /dev/null +++ b/acceptance/cmd/workspace/queries/test.toml @@ -0,0 +1,58 @@ +[[Server]] +Pattern = "GET /api/2.0/sql/queries" +Response.Body = ''' +{ + "results": [ + { + "description": "Example description", + "owner_user_name": "user@acme.com", + "tags": [ + "Tag 1" + ], + "display_name": "Example query 1", + "id": "ae25e731-92f2-4838-9fb2-1ca364320a3d", + "lifecycle_state": "ACTIVE", + "last_modifier_user_name": "user@acme.com", + "query_text": "SELECT 1", + "parameters": [ + { + "name": "foo", + "text_value": { + "value": "bar" + }, + "title": "foo" + } + ], + "update_time": "2019-08-24T14:15:22Z", + "warehouse_id": "a7066a8ef796be84", + "run_as_mode": "OWNER", + "create_time": "2019-08-24T14:15:22Z" + }, + { + "description": "Example description", + "owner_user_name": "user@acme.com", + "tags": [ + "Tag 1" + ], + "display_name": "Example query 2", + "id": "be25e731-92f2-4838-9fb2-1ca364320a3d", + "lifecycle_state": "ACTIVE", + "last_modifier_user_name": "user@acme.com", + "query_text": "SELECT 1", + "parameters": [ + { + "name": "foo", + "text_value": { + "value": "bar" + }, + "title": "foo" + } + ], + "update_time": "2019-08-24T14:15:22Z", + "warehouse_id": "a7066a8ef796be84", + "run_as_mode": "OWNER", + "create_time": "2019-08-24T14:15:22Z" + } + ] +} +''' diff --git a/cmd/workspace/queries/overrides.go b/cmd/workspace/queries/overrides.go index d7edf93a0..666cdfed5 100644 --- a/cmd/workspace/queries/overrides.go +++ b/cmd/workspace/queries/overrides.go @@ -11,7 +11,7 @@ func listOverride(listCmd *cobra.Command, listReq *sql.ListQueriesRequest) { listCmd.Annotations["headerTemplate"] = cmdio.Heredoc(` {{header "ID"}} {{header "Name"}} {{header "Author"}}`) listCmd.Annotations["template"] = cmdio.Heredoc(` - {{range .}}{{.Id|green}} {{.Name|cyan}} {{.User.Email|cyan}} + {{range .}}{{.Id|green}} {{.DisplayName|cyan}} {{.OwnerUserName|cyan}} {{end}}`) }