Skip to content

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

Fix QB crashing for mongo (#62585)

Alexander Polyankinff8e9786140a
diff --git a/src/metabase/lib/native.cljc b/src/metabase/lib/native.cljc
index 12a858da025..7364c78f853 100644
--- a/src/metabase/lib/native.cljc
+++ b/src/metabase/lib/native.cljc
@@ -175,12 +175,12 @@
results-metadata :- [:maybe ::lib.schema.metadata/stage]
native-extras :- [:maybe ::native-extras]]
(let [tags (extract-template-tags sql-or-other-native-query)]
- (-> (lib.query/query-with-stages metadata-providerable
- [{:lib/type :mbql.stage/native
- :lib/stage-metadata results-metadata
- :template-tags tags
- :native sql-or-other-native-query}])
- (with-native-extras native-extras)))))
+ (cond-> (lib.query/query-with-stages metadata-providerable
+ [{:lib/type :mbql.stage/native
+ :lib/stage-metadata results-metadata
+ :template-tags tags
+ :native sql-or-other-native-query}])
+ native-extras (with-native-extras native-extras)))))
(mu/defn with-different-database :- ::lib.schema/query
"Changes the database for this query. The first stage must be a native type.
diff --git a/test/metabase/lib/native_test.cljc b/test/metabase/lib/native_test.cljc
index fc22591aa96..be20eefe699 100644
--- a/test/metabase/lib/native_test.cljc
+++ b/test/metabase/lib/native_test.cljc
@@ -271,7 +271,10 @@
#?(:clj Throwable :cljs :default)
#"Must be a native query"
(-> (lib/query (metadata-provider-requiring-collection) (meta/table-metadata :venues))
- (lib/with-native-extras {:collection "mycollection"})))))
+ (lib/with-native-extras {:collection "mycollection"}))))
+ (testing "should not throw when creating a native query without required extras (metabase#62556)"
+ (is (=? {:stages [{:native "myquery"}]}
+ (lib/native-query (metadata-provider-requiring-collection) "myquery")))))
(deftest ^:parallel has-write-permission-test
(testing ":native-permissions in database"