Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
niwinz opened this issue Oct 28, 2024 · 1 comment
Closed

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

niwinz opened this issue Oct 28, 2024 · 1 comment

Comments

@niwinz
Copy link

niwinz commented Oct 28, 2024

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants