gcv / appengine-magic

A library designed to make it easy to use Google App Engine from Clojure
MIT License
342 stars 49 forks source link

NullPointerException on query #77

Open roti opened 10 years ago

roti commented 10 years ago

Hi,

Consider following:

(ds/defentity Item [^:key key-text value-text])

(ds/save! (new Item "one" "two"))

Then I evaluate following multiple times:

(ds/query :kind Item)

At the beginning everything works as expected (i.e. a sequence of one Item is returned). But after some time it throws following exception:

java.lang.NullPointerException: No API environment is registered for this thread.
    DatastoreApiHelper.java:80 com.google.appengine.api.datastore.DatastoreApiHelper.getCurrentAppId
    DatastoreApiHelper.java:90 com.google.appengine.api.datastore.DatastoreApiHelper.getCurrentAppIdNamespace
                Query.java:214 com.google.appengine.api.datastore.Query.<init>
                Query.java:143 com.google.appengine.api.datastore.Query.<init>
              (Unknown Source) sun.reflect.GeneratedConstructorAccessor14.newInstance
DelegatingConstructorAccessorImpl.java:45 sun.reflect.DelegatingConstructorAccessorImpl.newInstance
          Constructor.java:526 java.lang.reflect.Constructor.newInstance
            Reflector.java:180 clojure.lang.Reflector.invokeConstructor
             datastore.clj:261 appengine-magic.services.datastore/make-query-object
             datastore.clj:481 appengine-magic.services.datastore/query-helper

I have little knowlegde of the Datastore API, so I'm clueless here.

Răzvan

gcv commented 10 years ago

"No API environment is registered for this thread" generally means you have not started an App Engine instance in your REPL using ae/start, though I'm surprised things work for you the first time at all. Maybe you started the environment and it then crashed?

Also, make sure you are using the stable branch of appengine-magic with all its (old) dependencies — newer stuff on the master branch is not supported right now. https://github.com/gcv/appengine-magic/tree/v0.5.0

roti commented 10 years ago

I am using 0.5.1-SNAPSHOT (0.5.0 didn't work at all for me, I can't remember now why). I am using (ae/serve ...) to start the server. I don't think that the environment crashes without me noticing something, but I'll have a closer look anyway.

ezcocoa commented 10 years ago

It's same problem and 0.5.0 doesn't work on leiningen 2.0. So I am also using 0.5.1-SNAPSHOT, and Some time it throws Null point exception error.

gcv commented 10 years ago

Have you tried 0.5.0 and an earlier version of Leiningen? I have used that combination extensively, and have found it reliable. As I no longer use Google App Engine, 0.5.1-SNAPSHOT is still in (slow) development, and there isn't much I can do to help you track that down right now, unless you give me a clearly reproducible test case.