Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Name the Metabot notebook fallback apart from the SQL refusal it wraps (#85684)

Chris Truter2193439db43c
diff --git a/src/metabase/metabot/tools/sql.clj b/src/metabase/metabot/tools/sql.clj
index b37c9f72dfa..fc6f9d67e78 100644
--- a/src/metabase/metabot/tools/sql.clj
+++ b/src/metabase/metabot/tools/sql.clj
@@ -61,8 +61,8 @@
:mode "rewrite"
:value sql}))
-(tools/defrecoverable no-native-permission!
- "The user may not write SQL against the query's database, but can build the question in the notebook."
+(tools/defrecoverable no-native-permission-with-notebook-fallback!
+ "The user may not write SQL against the target database, and the notebook builder is offered this turn."
{:payload [:map {:closed true}]}
[_]
{:message "You do not have permission to write SQL against this database."
@@ -71,18 +71,18 @@
" this database again.")}]})
(defn- with-notebook-fallback
- "Call `thunk`. When it refuses SQL on a database and the notebook builder is available this turn,
- rethrow the refusal as [[no-native-permission!]], so the agent builds the question there instead
- of ending the turn. The SQL tools are offered to a user who may write SQL on any database, so the
- agent can still pick one where they may not. Without the notebook builder the refusal ends the
- turn."
+ "Call `thunk`, rethrowing its native-query refusal as [[no-native-permission-with-notebook-fallback!]]
+ when the notebook builder is offered this turn.
+ Without the notebook builder the refusal still ends the turn."
[ctx thunk]
+ ;; A user who may write SQL on any database gets the SQL tools, so the agent can pick a database where they may not.
+ ;; The recoverable error lets it try the notebook builder instead of ending the turn.
(try
(thunk)
(catch clojure.lang.ExceptionInfo e
(if (and (= ::sql.common/no-native-permission (get-in (ex-data e) [tools.error/error-key :code]))
(contains? (:tool-names ctx) "construct_notebook_query"))
- (tools.error/throw-recoverable! ::no-native-permission {} {:cause e})
+ (tools.error/throw-recoverable! ::no-native-permission-with-notebook-fallback {} {:cause e})
(throw e)))))
(defn- query-viz-part
diff --git a/test/metabase/metabot/tools/sql_test.clj b/test/metabase/metabot/tools/sql_test.clj
index 296899ec78f..4b778b3837d 100644
--- a/test/metabase/metabot/tools/sql_test.clj
+++ b/test/metabase/metabot/tools/sql_test.clj
@@ -242,7 +242,9 @@
(is (str/includes? (:output result) "Don't retry"))))
(testing (str tool-name " with the notebook builder")
(let [result (invoke :internal)]
- (is (= {:class :recoverable :code ::sql/no-native-permission} (:error result)))
+ (is (= {:class :recoverable
+ :code ::sql/no-native-permission-with-notebook-fallback}
+ (:error result)))
(is (str/includes? (:output result) "Build the question with `construct_notebook_query`")))))))))))
(deftest missing-sql-editor-test
@@ -285,7 +287,7 @@
[[:query-builder-and-native :internal nil]
[:query-builder-and-native :sql nil]
[:query-builder :internal {:class :recoverable
- :code ::sql/no-native-permission}]
+ :code ::sql/no-native-permission-with-notebook-fallback}]
[:query-builder :sql {:class :unrecoverable
:code ::sql.common/no-native-permission
:user-message "You do not have permission to write SQL queries against this database. Native query permissions are required."}]