This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-08-15
Channels
- # alda (1)
- # beginners (24)
- # biff (9)
- # calva (55)
- # cherry (1)
- # clj-kondo (36)
- # cljs-dev (3)
- # clojure (37)
- # clojure-austin (2)
- # clojure-brasil (1)
- # clojure-europe (14)
- # clojure-nl (1)
- # clojure-norway (24)
- # clojure-spec (3)
- # clojure-uk (1)
- # community-development (6)
- # core-typed (1)
- # datalevin (5)
- # datomic (28)
- # emacs (14)
- # events (1)
- # gratitude (9)
- # hyperfiddle (27)
- # instaparse (3)
- # joker (16)
- # lsp (89)
- # malli (24)
- # missionary (2)
- # nbb (5)
- # off-topic (59)
- # re-frame (12)
- # reitit (17)
- # releases (4)
- # sci (14)
- # spacemacs (1)
- # squint (7)
- # xtdb (41)
Hi! Looks like after https://github.com/metosin/malli/blob/master/CHANGELOG.md#0103-2023-03-18 mt/strip-extra-keys-transformer
started to strip all keys from :map
if there is no ::m/default
provided.
(m/decode
[:map]
{1 1, 2 "2", "3" 3, "4" "4"}
(mt/strip-extra-keys-transformer))
; => {}
Is it working as intended?if you don't mind, how do you expect it to work?
how did it work before?
haha classic
that's annoying
(m/decode
[:map]
{1 1, 2 "2", "3" 3, "4" "4"}
(mt/strip-extra-keys-transformer))
; => {1 1, 2 "2", "3" 3, "4" "4"}
i'm asking because to me, stripping all keys is the only way i can make sense of "map schema with no keys" plus "strip extra keys". if there are no defined keys, then every key is extra. for validation, :map
is completely open. but for stripping (coercion), idk if i agree
That is one way to think about it. The other way might be to think of [:map]
as an open map that might contain any key with any value. This way you get a map that might evolve for some time, before it could take final form.
But as I’ve said, I might be biased, because it just took a couple of hours of my life )
yeah for sure, i don't mean to discount the effort
Anyway, this change isn’t marked as breaking in changelog and my intent was to know if this effect was intended, and if it was, then propose to mark is as breaking.
I bet the folks at metosin would be willing to do that for you. they're responsive on github
Looks fishy. Just ending my 9 week vacation, have no memory of why that is changed. Looking at the CHANGELOG:
* mt/strip-extra-keys-transformer works with :map-of.
might have changed the behavior of :map
unintentionally. Please write an issue of this. I’ll check the commit messages if there is clue for this.https://github.com/metosin/malli/pull/871/commits/0e5b5e3ac56479f75c812c1320ac1f1ebfba8f76
(testing "extra keys from :map are stripped"
(is (= {:x 1, :y 2}
(m/decode
[:map [:x :int] [:y :int]]
{:x 1, :y 2, :z 3}
(mt/strip-extra-keys-transformer)))))
as maps are open by default, I think it’s bit odd to strip extra keys. For closed maps, sure.
Another side effect of this change is when you merge two map definitions and the first one has default key:
(def registry (merge (m/default-schemas) (mu/schemas)))
(def Merged
(m/schema
[:merge
[:map
[:x :string]
[::m/default [:map-of :keyword :any]]]
[:map {:closed true}
[:y :int]]]
{:registry registry}))
(m/validate Merged {:x "kikka", :y 6, :z "invalid"})
; => true
I.e. map is marked as closed, but it is not really closed.