weavejester / integrant

Micro-framework for data-driven architecture

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

init breaks on configs with ten or more keys and one reference

hagmonk opened this issue · comments

I couldn't for the life of me figure out what I'd broken, but eventually as I reduced my config down to almost nothing, I was able to find out where it's breaking. This is kind of a funny one :)

The following code will fail due to NPE.

(do
    (defmethod ig/init-key :a/a1 [_ _])
    (defmethod ig/init-key :a/a2 [_ _])
    (defmethod ig/init-key :a/a3 [_ -])
    (defmethod ig/init-key :a/a4 [_ -])
    (defmethod ig/init-key :a/a5 [_ -])
    (defmethod ig/init-key :a/a6 [_ -])
    (defmethod ig/init-key :a/a7 [_ -])
    (defmethod ig/init-key :a/a8 [_ -])
    (defmethod ig/init-key :a/a9 [_ -])
    (defmethod ig/init-key :a/a10 [_ _])

    (ig/init {:a/a1  {}
              :a/a2  {:_ (ig/ref :a/a1)}
              :a/a3  {}
              :a/a4  {}
              :a/a5  {}
              :a/a6  {}
              :a/a7  {}
              :a/a8  {}
              :a/a9  {}
              :a/a10 {}
              }
             ))

Comment out a single key in the map, and it will work. Or, remove the ig/ref and it will work. It's something to do with resolving references.

In the debugger I see:

(defn- resolve-ref [config ref]
  (val (first (find-derived config (:key ref)))))

... being invoked like this …

(val (first (ig/find-derived {:a/a4 4 :a/a6 6} :a/a1)))

Calling val on nil is what barfs, but how does it end up in this code path when the number of elements is >= 10?

Thanks for the report! I suspect this is a map ordering problem. Stupidly I replaced a reduce with a reduce-kv not thinking about the key order.

This shouldn't take too long to fix...

Okay, this should be fixed in 0.3.2.

I'm downloading it already! I owe you a beer at clojure/west if you'll be there.