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

Treat "" as ObjectId value equivalent to nil (#23580)

This is to enable is-empty and non-empty tests on :type/MongoBSONID columns.
parent 352a7d1a
No related branches found
No related tags found
No related merge requests found
......@@ -245,9 +245,10 @@
[[_ value {base-type :base_type}]]
(if (and (isa? base-type :type/MongoBSONID)
(some? value))
;; Passing a nil to the ObjectId constructor throws an exception
;; Passing nil or "" to the ObjectId constructor throws an exception
;; "invalid hexadecimal representation of an ObjectId: []" so, just treat it as nil
(ObjectId. (str value))
(when (not= value "")
(ObjectId. (str value)))
value))
(defn- $date-from-string [s]
......
......@@ -286,7 +286,20 @@
(rows (mt/dataset with-bson-ids
(mt/run-mbql-query birds
{:filter [:is-null $bird_id]}))))
"handle null ObjectId queries properly (#11134)"))))
"handle null ObjectId queries properly (#11134)")
(is (= [[3 "Unlucky Raven" nil]]
(rows (mt/dataset with-bson-ids
(mt/run-mbql-query birds
{:filter [:is-empty $bird_id]}))))
"treat null ObjectId as empty (#15801)")
(is (= [[1 "Rasta Toucan" (ObjectId. "012345678901234567890123")]
[2 "Lucky Pigeon" (ObjectId. "abcdefabcdefabcdefabcdef")]]
(rows (mt/dataset with-bson-ids
(mt/run-mbql-query birds
{:filter [:not-empty $bird_id]}))))
"treat non-null ObjectId as not-empty (#15801)"))))
(deftest bson-fn-call-forms-test
(mt/test-driver :mongo
......
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