weavejester / integrant

Micro-framework for data-driven architecture
MIT License
1.24k stars 63 forks source link

The expand-key does not exactly as a replacement for prep-key #112

Closed niwinz closed 1 week ago

niwinz commented 1 week ago

Hello,

On upgrading to integrant 0.13 (from 0.8), following the documentation, it suggests replace prep-key with expand-key. But they behave very differently on relation to types defined as records (because probably records behaves like a map and how expand-key performs a deep merge).

Having the following on the user ns:

(defmethod ig/expand-key ::foobar
  [k v]
  {k (assoc v :uri (map->UriLike {:schema "https" :host "hello.world" :path "/echo"}))})

(defmethod ig/prep-key ::foobar
  [_ v]
  (assoc v :uri (map->UriLike {:schema "https" :host "hello.world" :path "/echo"})))

I get the following:

user=> (ig/prep {:user/foobar {}})
#:user{:foobar {:uri #user.UriLike{:schema "https", :host "hello.world", :path "/echo"}}}
user=> (ig/expand {:user/foobar {}})
#:user{:foobar {:uri {:schema "https", :host "hello.world", :path "/echo"}}}

It is very unexpected from my point of view that a record data structure type is converted to a plain map when i use the expand mechanism suggested as replacement to the deprecated prep-key.

Is this expected behavior of expand or is a bug? With the current behavior of expand it can't be used as replacement because it has very different behavior and it has really a very purpose from my point of view.

weavejester commented 1 week ago

It's a bug. There should be a record? check when handling the expansion. I'll get it fixed and release 0.13.1.