Skip to content
Snippets Groups Projects
Unverified Commit 8e0c7765 authored by metamben's avatar metamben Committed by GitHub
Browse files

Handle rubbish in mongodb versionArray (#30879)

Fixes #29678.
parent ad6f5c0d
No related branches found
No related tags found
No related merge requests found
......@@ -183,9 +183,14 @@
(defmethod driver/dbms-version :mongo
[_ database]
(with-mongo-connection [^com.mongodb.DB conn database]
(let [build-info (mg/command conn {:buildInfo 1})]
(let [build-info (mg/command conn {:buildInfo 1})
version-array (get build-info "versionArray")
sanitized-version-array (into [] (take-while nat-int?) version-array)]
(when (not= (take 3 version-array) (take 3 sanitized-version-array))
(log/warnf "sanitizing versionArray %s results in %s, losing information"
version-array sanitized-version-array))
{:version (get build-info "version")
:semantic-version (get build-info "versionArray")})))
:semantic-version sanitized-version-array})))
(defmethod driver/describe-database :mongo
[_ database]
......
......@@ -21,6 +21,7 @@
[metabase.test.data.mongo :as tdm]
[metabase.util.log :as log]
[monger.collection :as mcoll]
[monger.core :as mg]
[taoensso.nippy :as nippy]
[toucan2.core :as t2])
(:import org.bson.types.ObjectId))
......@@ -488,3 +489,19 @@
(mt/rows
(mt/run-mbql-query bird_species
{:filter [:contains $bird_species._ "nett"]}))))))))
(deftest strange-versionArray-test
(mt/test-driver :mongo
(testing "Negative values in versionArray are ignored (#29678)"
(with-redefs [mg/command (constantly {"version" "4.0.28-23"
"versionArray" [4 0 29 -100]})]
(is (= {:version "4.0.28-23"
:semantic-version [4 0 29]}
(driver/dbms-version :mongo (mt/db))))))
(testing "Any values after rubbish in versionArray are ignored"
(with-redefs [mg/command (constantly {"version" "4.0.28-23"
"versionArray" [4 0 "NaN" 29]})]
(is (= {:version "4.0.28-23"
:semantic-version [4 0]}
(driver/dbms-version :mongo (mt/db))))))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment