Compojure Destructuring and Datomic lookup

102 views
Skip to first unread message

Vaso Vukotic

unread,
Mar 5, 2015, 11:52:10 PM3/5/15
to comp...@googlegroups.com
Concise question for the issue available here http://stackoverflow.com/questions/28890683/compojure-destructuring-making-integers-not-integers


Basically, I want to be able to navigate to localhost:4000/post1517172 where 1517172 is the post ID.

My handler.clj has the following relevant code:


   ;posts
  (GET "/post:id" [id :as request]
    ;(str "the blurb id is... " id)
    (def email (get-in request [:session :ze-auth-email]))
    (vb/post-page-draw email id))

Which returns a stacktrace.


Working code (where I have manually replaced the id in the call to  (vb/post-page-draw email id)


   ;posts
  (GET "/post:id" [id :as request]
    ;(str "the blurb id is... " id)
    (def email (get-in request [:session :ze-auth-email]))
    (vb/post-page-draw email 1517172))

the function invocation (vb/post-page-draw email 1517172) plays with Enlive and Datomic.  The number provided is the entity id and gets info from the Datomic local database.


My naming scheme is a little different ("blurbs" instead of "posts") but here is my stacktrace:

java.lang.Exception

processing rule: (q__7761 ?title ?content ?tags ?eid), message: processing clause: [?eid blurb/title ?title], message: Cannot resolve key: 17592186045616
datalog.clj:1440datomic.datalog/eval-rule[fn]
datalog.clj:1420datomic.datalog/eval-rule
datalog.clj:1463datomic.datalog/eval-query
datalog.clj:1552datomic.datalog/qsqr
datalog.clj:1509datomic.datalog/qsqr
query.clj:622datomic.query/q
api.clj:35datomic.api/q
RestFn.java:439clojure.lang.RestFn.invoke
dbmethods.clj:50pachax.database.dbmethods/get-blurb-by-eid
blurb.clj:24pachax.views.blurb/return-a-blurb
blurb.clj:70pachax.views.blurb/blurb-content-transform
blurb.clj:75pachax.views.blurb/blurb-page-draw
handler.clj:157pachax.handler/fn
core.clj:104compojure.core/make-route[fn]
core.clj:94compojure.core/wrap-route-middleware[fn]
core.clj:41compojure.core/if-route[fn]
core.clj:27compojure.core/if-method[fn]
core.clj:118compojure.core/routing[fn]
core.clj:2515clojure.core/some
core.clj:118compojure.core/routing
RestFn.java:139clojure.lang.RestFn.applyTo
core.clj:626clojure.core/apply
core.clj:123compojure.core/routes[fn]
Var.java:379clojure.lang.Var.invoke
handler.clj:254pachax.handler/logged-in-verify[fn]
response.clj:34compojure.response/eval1224[fn]
response.clj:7compojure.response/eval1183[fn]
core.clj:104compojure.core/make-route[fn]
core.clj:94compojure.core/wrap-route-middleware[fn]
core.clj:41compojure.core/if-route[fn]
core.clj:27compojure.core/if-method[fn]
core.clj:118compojure.core/routing[fn]
core.clj:2515clojure.core/some
core.clj:118compojure.core/routing
RestFn.java:139clojure.lang.RestFn.applyTo
core.clj:626clojure.core/apply
core.clj:123compojure.core/routes[fn]
flash.clj:35ring.middleware.flash/wrap-flash[fn]
anti_forgery.clj:90ring.middleware.anti-forgery/wrap-anti-forgery[fn]
session.clj:98ring.middleware.session/wrap-session[fn]
keyword_params.clj:35ring.middleware.keyword-params/wrap-keyword-params[fn]
nested_params.clj:84ring.middleware.nested-params/wrap-nested-params[fn]
multipart_params.clj:118ring.middleware.multipart-params/wrap-multipart-params[fn]
params.clj:64ring.middleware.params/wrap-params[fn]
cookies.clj:156ring.middleware.cookies/wrap-cookies[fn]
absolute_redirects.clj:36ring.middleware.absolute-redirects/wrap-absolute-redirects[fn]
resource.clj:26ring.middleware.resource/wrap-resource[fn]
content_type.clj:30ring.middleware.content-type/wrap-content-type[fn]
not_modified.clj:44ring.middleware.not-modified/wrap-not-modified[fn]
x_headers.clj:71ring.middleware.x-headers/wrap-xss-protection[fn]
x_headers.clj:38ring.middleware.x-headers/wrap-frame-options[fn]
x_headers.clj:53ring.middleware.x-headers/wrap-content-type-options[fn]
Var.java:379clojure.lang.Var.invoke
reload.clj:18ring.middleware.reload/wrap-reload[fn]
stacktrace.clj:17ring.middleware.stacktrace/wrap-stacktrace-log[fn]
stacktrace.clj:80ring.middleware.stacktrace/wrap-stacktrace-web[fn]
jetty.clj:18ring.adapter.jetty/proxy-handler[fn]
(Unknown Source)ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle
HandlerWrapper.java:116org.eclipse.jetty.server.handler.HandlerWrapper.handle
Server.java:363org.eclipse.jetty.server.Server.handle
AbstractHttpConnection.java:483org.eclipse.jetty.server.AbstractHttpConnection.handleRequest
AbstractHttpConnection.java:920org.eclipse.jetty.server.AbstractHttpConnection.headerComplete
AbstractHttpConnection.java:982org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete
HttpParser.java:635org.eclipse.jetty.http.HttpParser.parseNext
HttpParser.java:235org.eclipse.jetty.http.HttpParser.parseAvailable
AsyncHttpConnection.java:82org.eclipse.jetty.server.AsyncHttpConnection.handle
SelectChannelEndPoint.java:628org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle
SelectChannelEndPoint.java:52org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run
QueuedThreadPool.java:608org.eclipse.jetty.util.thread.QueuedThreadPool.runJob
QueuedThreadPool.java:543org.eclipse.jetty.util.thread.QueuedThreadPool$3.run
Thread.java:745java.lang.Thread.run

Caused by java.lang.Exception

processing clause: [?eid blurb/title ?title], message: Cannot resolve key: 17592186045616
datalog.clj:1386datomic.datalog/eval-clause[fn]
datalog.clj:1349datomic.datalog/eval-clause
datalog.clj:1435datomic.datalog/eval-rule[fn]
datalog.clj:1420datomic.datalog/eval-rule
datalog.clj:1463datomic.datalog/eval-query
datalog.clj:1552datomic.datalog/qsqr
datalog.clj:1509datomic.datalog/qsqr
query.clj:622datomic.query/q
api.clj:35datomic.api/q
RestFn.java:439clojure.lang.RestFn.invoke
dbmethods.clj:50pachax.database.dbmethods/get-blurb-by-eid
blurb.clj:24pachax.views.blurb/return-a-blurb
blurb.clj:70pachax.views.blurb/blurb-content-transform
blurb.clj:75pachax.views.blurb/blurb-page-draw
handler.clj:157pachax.handler/fn
core.clj:104compojure.core/make-route[fn]
core.clj:94compojure.core/wrap-route-middleware[fn]
core.clj:41compojure.core/if-route[fn]
core.clj:27compojure.core/if-method[fn]
core.clj:118compojure.core/routing[fn]
core.clj:2515clojure.core/some
core.clj:118compojure.core/routing
RestFn.java:139clojure.lang.RestFn.applyTo
core.clj:626clojure.core/apply
core.clj:123compojure.core/routes[fn]
Var.java:379clojure.lang.Var.invoke
handler.clj:254pachax.handler/logged-in-verify[fn]
response.clj:34compojure.response/eval1224[fn]
response.clj:7compojure.response/eval1183[fn]
core.clj:104compojure.core/make-route[fn]
core.clj:94compojure.core/wrap-route-middleware[fn]
core.clj:41compojure.core/if-route[fn]
core.clj:27compojure.core/if-method[fn]
core.clj:118compojure.core/routing[fn]
core.clj:2515clojure.core/some
core.clj:118compojure.core/routing
RestFn.java:139clojure.lang.RestFn.applyTo
core.clj:626clojure.core/apply
core.clj:123compojure.core/routes[fn]
flash.clj:35ring.middleware.flash/wrap-flash[fn]
anti_forgery.clj:90ring.middleware.anti-forgery/wrap-anti-forgery[fn]
session.clj:98ring.middleware.session/wrap-session[fn]
keyword_params.clj:35ring.middleware.keyword-params/wrap-keyword-params[fn]
nested_params.clj:84ring.middleware.nested-params/wrap-nested-params[fn]
multipart_params.clj:118ring.middleware.multipart-params/wrap-multipart-params[fn]
params.clj:64ring.middleware.params/wrap-params[fn]
cookies.clj:156ring.middleware.cookies/wrap-cookies[fn]
absolute_redirects.clj:36ring.middleware.absolute-redirects/wrap-absolute-redirects[fn]
resource.clj:26ring.middleware.resource/wrap-resource[fn]
content_type.clj:30ring.middleware.content-type/wrap-content-type[fn]
not_modified.clj:44ring.middleware.not-modified/wrap-not-modified[fn]
x_headers.clj:71ring.middleware.x-headers/wrap-xss-protection[fn]
x_headers.clj:38ring.middleware.x-headers/wrap-frame-options[fn]
x_headers.clj:53ring.middleware.x-headers/wrap-content-type-options[fn]
Var.java:379clojure.lang.Var.invoke
reload.clj:18ring.middleware.reload/wrap-reload[fn]
stacktrace.clj:17ring.middleware.stacktrace/wrap-stacktrace-log[fn]
stacktrace.clj:80ring.middleware.stacktrace/wrap-stacktrace-web[fn]
jetty.clj:18ring.adapter.jetty/proxy-handler[fn]
(Unknown Source)ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle
HandlerWrapper.java:116org.eclipse.jetty.server.handler.HandlerWrapper.handle
Server.java:363org.eclipse.jetty.server.Server.handle
AbstractHttpConnection.java:483org.eclipse.jetty.server.AbstractHttpConnection.handleRequest
AbstractHttpConnection.java:920org.eclipse.jetty.server.AbstractHttpConnection.headerComplete
AbstractHttpConnection.java:982org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete
HttpParser.java:635org.eclipse.jetty.http.HttpParser.parseNext
HttpParser.java:235org.eclipse.jetty.http.HttpParser.parseAvailable
AsyncHttpConnection.java:82org.eclipse.jetty.server.AsyncHttpConnection.handle
SelectChannelEndPoint.java:628org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle
SelectChannelEndPoint.java:52org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run
QueuedThreadPool.java:608org.eclipse.jetty.util.thread.QueuedThreadPool.runJob
QueuedThreadPool.java:543org.eclipse.jetty.util.thread.QueuedThreadPool$3.run
Thread.java:745java.lang.Thread.run

Caused by java.lang.IllegalArgumentException

Cannot resolve key: 17592186045616
datalog.clj:260datomic.datalog/resolve-id
datalog.clj:267datomic.datalog/dbrel
datalog.clj:314datomic.datalog/fn
datalog.clj:278datomic.datalog/fn[fn]
datalog.clj:1355datomic.datalog/eval-clause[fn]
datalog.clj:1349datomic.datalog/eval-clause
datalog.clj:1435datomic.datalog/eval-rule[fn]
datalog.clj:1420datomic.datalog/eval-rule
datalog.clj:1463datomic.datalog/eval-query
datalog.clj:1552datomic.datalog/qsqr
datalog.clj:1509datomic.datalog/qsqr
query.clj:622datomic.query/q
api.clj:35datomic.api/q
RestFn.java:439clojure.lang.RestFn.invoke
dbmethods.clj:50pachax.database.dbmethods/get-blurb-by-eid
blurb.clj:24pachax.views.blurb/return-a-blurb
blurb.clj:70pachax.views.blurb/blurb-content-transform
blurb.clj:75pachax.views.blurb/blurb-page-draw
handler.clj:157pachax.handler/fn
core.clj:104compojure.core/make-route[fn]
core.clj:94compojure.core/wrap-route-middleware[fn]
core.clj:41compojure.core/if-route[fn]
core.clj:27compojure.core/if-method[fn]
core.clj:118compojure.core/routing[fn]
core.clj:2515clojure.core/some
core.clj:118compojure.core/routing
RestFn.java:139clojure.lang.RestFn.applyTo
core.clj:626clojure.core/apply
core.clj:123compojure.core/routes[fn]
Var.java:379clojure.lang.Var.invoke
handler.clj:254pachax.handler/logged-in-verify[fn]
response.clj:34compojure.response/eval1224[fn]
response.clj:7compojure.response/eval1183[fn]
core.clj:104compojure.core/make-route[fn]
core.clj:94compojure.core/wrap-route-middleware[fn]
core.clj:41compojure.core/if-route[fn]
core.clj:27compojure.core/if-method[fn]
core.clj:118compojure.core/routing[fn]
core.clj:2515clojure.core/some
core.clj:118compojure.core/routing
RestFn.java:139clojure.lang.RestFn.applyTo
core.clj:626clojure.core/apply
core.clj:123compojure.core/routes[fn]
flash.clj:35ring.middleware.flash/wrap-flash[fn]
anti_forgery.clj:90ring.middleware.anti-forgery/wrap-anti-forgery[fn]
session.clj:98ring.middleware.session/wrap-session[fn]
keyword_params.clj:35ring.middleware.keyword-params/wrap-keyword-params[fn]
nested_params.clj:84ring.middleware.nested-params/wrap-nested-params[fn]
multipart_params.clj:118ring.middleware.multipart-params/wrap-multipart-params[fn]
params.clj:64ring.middleware.params/wrap-params[fn]
cookies.clj:156ring.middleware.cookies/wrap-cookies[fn]
absolute_redirects.clj:36ring.middleware.absolute-redirects/wrap-absolute-redirects[fn]
resource.clj:26ring.middleware.resource/wrap-resource[fn]
content_type.clj:30ring.middleware.content-type/wrap-content-type[fn]
not_modified.clj:44ring.middleware.not-modified/wrap-not-modified[fn]
x_headers.clj:71ring.middleware.x-headers/wrap-xss-protection[fn]
x_headers.clj:38ring.middleware.x-headers/wrap-frame-options[fn]
x_headers.clj:53ring.middleware.x-headers/wrap-content-type-options[fn]
Var.java:379clojure.lang.Var.invoke
reload.clj:18ring.middleware.reload/wrap-reload[fn]
stacktrace.clj:17ring.middleware.stacktrace/wrap-stacktrace-log[fn]
stacktrace.clj:80ring.middleware.stacktrace/wrap-stacktrace-web[fn]
jetty.clj:18ring.adapter.jetty/proxy-handler[fn]
(Unknown Source)ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle
HandlerWrapper.java:116org.eclipse.jetty.server.handler.HandlerWrapper.handle
Server.java:363org.eclipse.jetty.server.Server.handle
AbstractHttpConnection.java:483org.eclipse.jetty.server.AbstractHttpConnection.handleRequest
AbstractHttpConnection.java:920org.eclipse.jetty.server.AbstractHttpConnection.headerComplete
AbstractHttpConnection.java:982org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete
HttpParser.java:635org.eclipse.jetty.http.HttpParser.parseNext
HttpParser.java:235org.eclipse.jetty.http.HttpParser.parseAvailable
AsyncHttpConnection.java:82org.eclipse.jetty.server.AsyncHttpConnection.handle
SelectChannelEndPoint.java:628org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle
SelectChannelEndPoint.java:52org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run
QueuedThreadPool.java:608org.eclipse.jetty.util.thread.QueuedThreadPool.runJob
QueuedThreadPool.java:543org.eclipse.jetty.util.thread.QueuedThreadPool$3.run
Thread.java:745java.lang.Thread.run


Any ideas on how I can fix this, or alternately how I can get the desired behavior?
Thanks in advance!

James Reeves

unread,
Mar 6, 2015, 12:03:04 AM3/6/15
to Compojure
First of all, you're using "def" wrong. "def" defines a top-level var in the current namespace. It isn't local assignment. You want to use "let" instead.

Secondly, the type of the arguments change between your two examples. In the first example you pass in a string containing a number. In the second example you pass in the number directly (as a long).

You want something more like:

    (GET "/post:id" [id :as request]
      (let [email (get-in request [:session :ze-auth-email])]
        (vb/post-page-draw email (Long/parseLong id))))

- James

--
You received this message because you are subscribed to the Google Groups "Compojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to compojure+...@googlegroups.com.
To post to this group, send email to comp...@googlegroups.com.
Visit this group at http://groups.google.com/group/compojure.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages