Skip to content

Commit

Permalink
Fix nil schema in /api/table/:id/query_metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ranquild committed Apr 4, 2024
1 parent 8c6cdd9 commit 9430478
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/metabase/api/table.clj
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,17 @@
"Schema for a valid table field ordering."
(into [:enum] (map name table/field-orderings)))

(defn- format-table-for-response [table]
;; for `nil` schemas return the empty string
(update table :schema #(if (nil? %) "" %)))

(api/defendpoint GET "/"
"Get all `Tables`."
[]
(as-> (t2/select Table, :active true, {:order-by [[:name :asc]]}) tables
(t2/hydrate tables :db)
(filterv mi/can-read? tables)))
(filterv mi/can-read? tables)
(mapv format-table-for-response)))

(api/defendpoint GET "/:id"
"Get `Table` with ID."
Expand All @@ -57,7 +62,8 @@
api/write-check
api/read-check)]
(-> (api-perm-check-fn Table id)
(t2/hydrate :db :pk_field))))
(t2/hydrate :db :pk_field)
format-table-for-response)))

(defn- update-table!*
"Takes an existing table and the changes, updates in the database and optionally calls `table/update-field-positions!`
Expand Down Expand Up @@ -331,9 +337,8 @@
(t2/hydrate :db [:fields [:target :has_field_values] :dimensions :has_field_values] :segments :metrics)
(m/dissoc-in [:db :details])
(assoc-dimension-options db)
format-table-for-response
format-fields-for-response
;; for `nil` schemas return the empty string
(update :schema #(if (nil? %) "" %))
(update :fields (partial filter (fn [{visibility-type :visibility_type}]
(case (keyword visibility-type)
:hidden include-hidden-fields?
Expand Down

0 comments on commit 9430478

Please sign in to comment.