malli icon indicating copy to clipboard operation
malli copied to clipboard

When parsing, the parsed value is passed into validation functions, causing failure to parse even on schemas that validate.

Open escherize opened this issue 1 year ago • 0 comments

It seems like this is not the intended behavior, but here's what I am seeing locally:

These print different things, but that's not a big problem:

(mc/validate [:and [:catn ["a" :int] ["b" :keyword]]
              [:fn (fn [x] (prn x) true)]]
             [3 :x])
;; prints: [3 :x]
;; => true

(mc/parse [:and [:catn ["a" :int] ["b" :keyword]]
           [:fn (fn [x] (prn x) true)]]
          [3 :x])
;; prints: {"a" 3, "b" :x}
;; => {"a" 3, "b" :x}

The problem I'm hitting is when we actually try to validate these things with the attached :fn schema:

(mc/validate [:and [:catn ["a" :int] ["b" :keyword]]
              [:fn vector?]]
             [3 :x])
;; true

(mc/parse [:and [:catn ["a" :int] ["b" :keyword]]
           [:fn vector?]]
          [3 :x])
;; => :malli.core/invalid 😢 

I sort of can work around it by checking for e.g. (if it's a map with these keys, then it passes validation). but that's not really ideal.

escherize avatar Jan 28 '25 21:01 escherize