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

cannot read property 1 of null #44

Closed
jdkealy opened this issue Dec 21, 2014 · 3 comments
Closed

cannot read property 1 of null #44

jdkealy opened this issue Dec 21, 2014 · 3 comments

Comments

@jdkealy
Copy link

jdkealy commented Dec 21, 2014

When I pass in a rule with a function to match a regex, I can call the function multiple times with different inputs so long as the attribute exists in all datoms. I can call the function once even when the attribute does not exist in all datoms. I get a long obscure error if I call the function multiple times when the attribute does not exist in all datoms. My test attribute here is :photo/does_not_exist.

(def test-schema {})
(def test-conn (d/create-conn schema))
(defn matcher-func [input to-match]
(re-find (re-pattern (.toLowerCase (clj->js input))) (.toLowerCase (clj->js to-match))))

(let [tx (d/transact! test-conn [{:db/id 1 :photo/thumb "foo.jpg" :photo/name "AAA" :photo/caption "BBB"}
                               {:db/id 2 :photo/thumb "bar.jpg" :photo/name "DDD" :photo/caption "AAA"}])]

;calling the function once with missing attributes
(d/q '{:find [?p]
       :in [$ % ?match-func]
       :where
       [[?p :photo/thumb _]
        (findall ?match-func ?p "a")]}
     @test-conn
     '[[(findall ?match-func ?p ?input) [?p :photo/name ?pn][(?match-func ?input ?pn)]]
       [(findall ?match-func ?p ?input) [?p :photo/caption ?pn][(?match-func ?input ?pn)]]
       [(findall ?match-func ?p ?input) [?p :photo/does_not_exist ?pn][(?match-func ?input ?pn)]]]
     matcher-func)

{[2] [1]}

  ;calling the function twice without missing attributes
  (d/q '{:find [?p]
       :in [$ % ?match-func]
       :where
       [[?p :photo/thumb _]
        (findall ?match-func ?p "a")
        (findall ?match-func ?p "b")]}
     @test-conn
     '[[(findall ?match-func ?p ?input) [?p :photo/name ?pn][(?match-func ?input ?pn)]]
       [(findall ?match-func ?p ?input) [?p :photo/caption ?pn][(?match-func ?input ?pn)]]]
     matcher-func)

#{[1]}

;calling the function twice with missing attributes
(d/q '{:find [?p]
       :in [$ % ?match-func]
       :where
       [[?p :photo/thumb _]
        (findall ?match-func ?p "a")
        (findall ?match-func ?p "b")]}
     @test-conn
     '[[(findall ?match-func ?p ?input) [?p :photo/name ?pn][(?match-func ?input ?pn)]]
       [(findall ?match-func ?p ?input) [?p :photo/caption ?pn][(?match-func ?input ?pn)]]
       [(findall ?match-func ?p ?input) [?p :photo/does_not_exist ?pn][(?match-func ?input ?pn)]]]
     matcher-func))

"Error evaluating:" (d/q (quote {:find [?p], :in [$ % ?match-func], :where [[?p :photo/thumb ](findall ?match-func ?p) (findall ?match-func ?p "b")]}) (clojure.core/deref test-conn) (quote [[(findall ?match-func ?p ?input) [?p :photo/name ?pn] [(?match-func ?input ?pn)]] [(findall ?match-func ?p ?input) [?p :photo/caption ?pn] [(?match-func ?input ?pn)]] [(findall ?match-func ?p ?input) [?p :photo/does_not_exist ?pn] [(?match-func ?input ?pn)]]]) matcher-func) :as "datascript.q.call(null,new cljs.core.PersistentArrayMap(null, 3, [new cljs.core.Keyword(null,"find","find",496279456),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Symbol(null,"?p","?p",-10896580,null)], null),new cljs.core.Keyword(null,"in","in",-1531184865),new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Symbol(null,"$","$",-1580747756,null),new cljs.core.Symbol(null,"%","%",-950237169,null),new cljs.core.Symbol(null,"?ma
tch-func","?match-func",2022652070,null)], null),new cljs.core.Keyword(null,"where","where",-2044795965),new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Symbol(null,"?p","?p",-10896580,null),new cljs.core.Keyword("photo","thumb","photo/thumb",1624132066),new cljs.core.Symbol(null,"
","_",-1201019570,null)], null),cljs.core.list(new cljs.core.Symbol(null,"findall","findall",1888933708,null),new cljs.core.Symbol(null,"?match-func","?match-func",2022652070,null),new cljs.core.Symbol(null,"?p","?p",-10896580,null),"a"),cljs.core.list(new cljs.core.Symbol(null,"findall","findall",1888933708,null),new cljs.core.Symbol(null,"?match-func","?match-func",2022652070,null),new cljs.core.Symbol(null,"?p","?p",-10896580,null),"b")], null)], null),cljs.core.deref.call(null,blakbox.api.test_conn),new cljs.core.PersistentVector(null, 3, 5, cljs.cor
e.PersistentVector.EMPTY_NODE, [new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.list(new cljs.core.Symbol(null,"findall","findall",1888933708,null),new cljs.core.Symbol(null,"?match-func","?match-func",2022652070,null),new cljs.core.Symbol(null,"?p","?p",-10896580,null),new cljs.core.Symbol(null,"?input","?input",-405387186,null)),new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Symbol(null,"?p","?p",-10896580,null),new cljs.core.Keyword("photo","name","photo/name",1599012447),new cljs.core.Symbol(null,"?pn","?pn",704318294,null)], null),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.list(new cljs.core.Symbol(null,"?match-func","?match-func",2022652070,null),new cljs.core.Symbol(null,"?input","?input",-405387186,null),new cljs.core.Symbol(null,"?pn","?pn",704318294,null))], null)], null),new cljs.core.PersistentVector(null, 3, 5, c
ljs.core.PersistentVector.EMPTY_NODE, [cljs.core.list(new cljs.core.Symbol(null,"findall","findall",1888933708,null),new cljs.core.Symbol(null,"?match-func","?match-func",2022652070,null),new cljs.core.Symbol(null,"?p","?p",-10896580,null),new cljs.core.Symbol(null,"?input","?input",-405387186,null)),new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Symbol(null,"?p","?p",-10896580,null),new cljs.core.Keyword("photo","caption","photo/caption",-978411948),new cljs.core.Symbol(null,"?pn","?pn",704318294,null)], null),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.list(new cljs.core.Symbol(null,"?match-func","?match-func",2022652070,null),new cljs.core.Symbol(null,"?input","?input",-405387186,null),new cljs.core.Symbol(null,"?pn","?pn",704318294,null))], null)], null),new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.list(new cljs.core.Sy
mbol(null,"findall","findall",1888933708,null),new cljs.core.Symbol(null,"?match-func","?match-func",2022652070,null),new cljs.core.Symbol(null,"?p","?p",-10896580,null),new cljs.core.Symbol(null,"?input","?input",-405387186,null)),new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Symbol(null,"?p","?p",-10896580,null),new cljs.core.Keyword("photo","does_not_exist","photo/does_not_exist",-133167301),new cljs.core.Symbol(null,"?pn","?pn",704318294,null)], null),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.list(new cljs.core.Symbol(null,"?match-func","?match-func",2022652070,null),new cljs.core.Symbol(null,"?input","?input",-405387186,null),new cljs.core.Symbol(null,"?pn","?pn",704318294,null))], null)], null)], null),blakbox.api.matcher_func);\n"

<TypeError: Cannot read property '1' of null>

TypeError: Cannot read property '1' of null
at context_resolve_val (http://localhost:8080/js/out/datascript/query.js:1097:127)
at http://localhost:8080/js/out/datascript/query.js:1142:45
at filter_by_pred (http://localhost:8080/js/out/datascript/query.js:1144:3)
at _resolve_clause (http://localhost:8080/js/out/datascript/query.js:1514:40)
at cljs.core.seq_reduce.seq_reduce__3 (http://localhost:8080/js/out/cljs/core.js:6463:14)
at cljs.core.seq_reduce.seq_reduce (http://localhost:8080/js/out/cljs/core.js:6484:22)
at cljs.core.LazySeq.cljs$core$IReduce$_reduce$arity$3 (http://localhost:8080/js/out/cljs/core.js:9200:29)
at cljs.core._reduce._reduce__3 (http://localhost:8080/js/out/cljs/core.js:1805:13)
at cljs.core._reduce._reduce (http://localhost:8080/js/out/cljs/core.js:1827:19)
at cljs.core.reduce.reduce__3 (http://localhost:8080/js/out/cljs/core.js:6559:26)

@tonsky
Copy link
Owner

tonsky commented Dec 22, 2014

I can reproduce that, thx, looking into right now

@tonsky tonsky closed this as completed in 1f34f87 Dec 22, 2014
@tonsky
Copy link
Owner

tonsky commented Dec 22, 2014

Fixed in 0.7.2, thanks for the heads-up!

@jdkealy
Copy link
Author

jdkealy commented Dec 22, 2014

AMAZING!

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