-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
Test ns fails to load defrecord with "Could not resolve symbol" error for a protocol's method name #914
Comments
Is it possible to make a smaller repro? |
@logseq-cldwalker Perhaps you're able to make a reproduction using the sci.configs playground where datascript is available: |
Sure. Taking a look shortly |
@borkdude I created repro at https://github.com/logseq-cldwalker/sci.configs/tree/storage-test-failing-repro. When I copy in the defprotocol and eval in the playground, I get the same result: To repro locally:
(defrecord Storage [*disk *reads *writes *deletes]
d.storage/IStorage
(-store [_ addr+data-seq]
(doseq [[addr data] addr+data-seq]
(vswap! *disk assoc addr (pr-str data))
(vswap! *writes conj addr)))
(-restore [_ addr]
(vswap! *reads conj addr)
(-> @*disk (get addr) edn/read-string))) |
I think Another issue is that SCI protocols are implemented different (using multimethods) than protocols in CLJS. |
I'm seeing IStorage and -storage vars in the output. Are you referring to some other var? I see I'm able to load a reified version of the protocol e.g.: (reify d.storage/IStorage
(-store [_ addr+data-seq]
(let [data (map
(fn [[addr data]]
#js {:$addr addr
:$content (pr-str data)})
addr+data-seq)]
(identity data)))
(-restore [_ addr]
(identity addr))) |
Alright, I'll try locally |
There is something wonky going on with a
but this just boils down to the problem stated before:
Protocols in SCI are implemented using multimethods. You can see how this works in SCI itself for Related issue: #639 |
@logseq-cldwalker I pushed a partial solution here: https://github.com/babashka/sci.configs/tree/storage-test-failing-repro The latest commit shows how to expose an existing protocol using a wrapper. Note that any function that calls A more proper solution would be to let SCI alter existing CLJS protocols, but perhaps this will work for you in the meanwhile? I know that @phronmophobic has found a way to do this with CLJ protocols here: https://github.com/phronmophobic/scify |
Thanks for finding the cause and a workaround! (defrecord Storage [*disk *reads *writes *deletes]
d.storage/IStorage
(-store [_ addr+data-seq]
(doseq [[addr data] addr+data-seq]
(vswap! *disk assoc addr (pr-str data))
(vswap! *writes conj addr)))
(-restore [_ addr]
(vswap! *reads conj addr)
(-> @*disk (get addr) edn/read-string)))
(defn make-storage [& [opts]]
(map->Storage
{:*disk (volatile! {})
:*reads (volatile! [])
:*writes (volatile! [])
:*deletes (volatile! [])}))
(let [db (d/empty-db)
storage (make-storage)]
(d/store db storage))
How would I do that?
This should work as we're running a datascript fork for now. Eventually we'd like to be contribute back our changes and use standard datascript |
I'll try it out and push a change. |
Pushed a patch upstream: https://github.com/babashka/sci.configs/tree/storage-test-failing-repro Note that I patched datascript's |
Thanks! The last code snippet loads and works correctly. I'm also trying to use (def s1
(reify d.storage/IStorage
(-store [_ addr+data-seq]
(let [data (map
(fn [[addr data]]
#js {:$addr addr
:$content (pr-str data)})
addr+data-seq)]
(identity data)))
(-restore [_ addr]
(identity addr))))
(d/restore-conn s1) Is there another workaround with protocols that I'd need to do?
I didn't realize the patch was just in sci. I take back what I said and think this could be a long term solution as the protocols don't change much and wouldn't effect an upstream contribution to datascript |
For reify another workaround is possible I believe. Let's see... |
Fixed |
For next issues, could you please paste a full repro including the |
Sure. Sorry. Will do Datascript storage tests and nbb logseq tests passing with the last patch. Thanks! Happy to add some docs next week on protocol patching if it's helpful. I could inline examples or refer to the ones of the sci.configs branch |
The protocol patching relies on quite a bit of implementation details which perhaps can be made public. |
Hi @borkdude. As discussed in slack, here's a repro that passes for cljs but fails for nbb + sci
version
0.8.41
platform
osx 12 with node
problem
After building a custom version of nbb with sci configs for this datascript fork, the nbb build is unable to load this datascript test ns
repro
bb release
bb test
and see:If it's helpful, https://github.com/logseq/datascript/blob/logseq/test-storage/src/datascript/storage.cljs is the source for
datascript.storage
and was copied into sci withsci/copy-ns
expected behavior
I expected to see the 2 unit tests pass like they do in cljs. Run the same test ns with cljs using:
cd test/libraries/datascript && yarn install && clj -M:shadow-cljs:test compile test && node target/datascript.js
This repro could be more minimal if all the deftests and defns are removed from the test ns. I left them in order to see correct behavior for the tests
Sponsor - I think so. We/logseq sponsor babashka and indirectly via Clojurists Together
The text was updated successfully, but these errors were encountered: