HiddenStage / divide

Apache License 2.0
280 stars 26 forks source link

App Engine queries for >, >=, <, and <= are returning 500 error #6

Open 6thSigma opened 9 years ago

6thSigma commented 9 years ago

Query:

Query query = new QueryBuilder()
    .select()
    .from(Pizza.class)
    .where("NumberOfToppings", OPERAND.GREATER_THAN, "2")
    .build();

BackendServices.remote()
    .query(Pizza.class, query)
    .subscribe(new Action1<Collection<Pizza>>() {
        @Override
         public void call(Collection<Pizza> objects) {
             Log.d(TAG, objects.toString());
         }
});

Error from Android:

10-03 10:26:07.986  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:---> HTTP POST https://empyrean-bridge-687.appspot.com/api/data/query
10-03 10:26:07.986  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:Authorization: CUSTOM WUphdEVFdUpyZnlaTEJxYTJHcTE5bnh5QzVLZDRpcVlCdkMrdzIrdWxNZW82NEdRbktiMmRKdVZzK2dqcGZWdE1PQlh2WXZ6bjFVZUNSNllkSk9PZlE9PQ==
10-03 10:26:07.986  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:Content-Type: application/json; charset=UTF-8
10-03 10:26:07.986  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:Content-Length: 156
10-03 10:26:07.986  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:
10-03 10:26:07.986  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:{"action":"SELECT","from":"io_divide_sampleapp_Pizza","where":{"0":{"after":"2","before":"user_data.NumberOfToppings","operand":"\u003e","preOperator":""}}}
10-03 10:26:07.986  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:---> END HTTP (156-byte body)
10-03 10:26:08.146  31964-31995/io.divide.sampleapp W/System.err﹕ Retrofit:afterCall(/data/query:POST: 500 : null
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:<--- HTTP 500 https://empyrean-bridge-687.appspot.com/api/data/query (156ms)
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:: HTTP/1.1 500 Internal Server Error
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:alternate-protocol: 443:quic,p=0.01
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:cache-control: private
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:content-type: text/html; charset=utf-8
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:date: Fri, 03 Oct 2014 15:26:08 GMT
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:OkHttp-Received-Millis: 1412349968156
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:OkHttp-Response-Source: NETWORK 500
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:OkHttp-Selected-Protocol: spdy/3.1
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:OkHttp-Sent-Millis: 1412349968003
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:server: Google Frontend
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:vary: Accept-Encoding
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:<html><head>
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ <meta http-equiv="content-type" content="text/html;charset=utf-8">
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ <title>500 Request failed.</title>
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ </head>
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ <body text=#000000 bgcolor=#ffffff>
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ <h1>Error: Request failed.</h1>
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ </body></html>
10-03 10:26:08.146  31964-31995/io.divide.sampleapp I/System.out﹕ Retrofit:<--- END HTTP (206-byte body)
10-03 10:26:08.146  31964-31964/io.divide.sampleapp D/AndroidRuntime﹕ Shutting down VM
10-03 10:26:08.146  31964-31964/io.divide.sampleapp W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x415d7ce0)
10-03 10:26:08.156  31964-31964/io.divide.sampleapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: io.divide.sampleapp, PID: 31964
    rx.exceptions.OnErrorNotImplementedException: 500 Internal Server Error
            at rx.Observable$26.onError(Observable.java:6678)
            at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:135)
            at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:103)
            at rx.internal.operators.NotificationLite.accept(NotificationLite.java:144)
            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.pollQueue(OperatorObserveOn.java:141)
            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.access$000(OperatorObserveOn.java:61)
            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber$1.call(OperatorObserveOn.java:123)
            at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:43)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5139)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: retrofit.RetrofitError: 500 Internal Server Error
            at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:382)
            at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
            at $Proxy8.query(Native Method)
            at io.divide.client.data.DataManager$2.call(DataManager.java:100)
            at io.divide.client.data.DataManager$2.call(DataManager.java:96)
            at rx.Observable.unsafeSubscribe(Observable.java:6839)
            at rx.internal.operators.OperatorSubscribeOn$1$1.call(OperatorSubscribeOn.java:60)
            at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:43)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
            at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:841)

Error from App Engine:

10:26:08.918 /api/data/query
com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found.
The suggested index for this query is:
    <datastore-index kind="OfyObject" ancestor="false" source="manual">
        <property name="meta_data.object_type" direction="asc"/>
        <property name="user_data.NumberOfToppings" direction="asc"/>
    </datastore-index>

    at com.google.appengine.api.datastore.DatastoreApiHelper.translateError(DatastoreApiHelper.java:51)
    at com.google.appengine.api.datastore.DatastoreApiHelper$AsyncCallWrapper.convertException(DatastoreApiHelper.java:74)
    at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:96)
    at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:88)
    at com.google.appengine.api.datastore.FutureHelper.getInternal(FutureHelper.java:71)
    at com.google.appengine.api.datastore.FutureHelper.quietGet(FutureHelper.java:32)
    at com.google.appengine.api.datastore.BaseQueryResultsSource.getIndexList(BaseQueryResultsSource.java:152)
    at com.google.appengine.api.datastore.BaseQueryResultsSource.loadMoreEntities(BaseQueryResultsSource.java:181)
    at com.google.appengine.api.datastore.BaseQueryResultsSource.loadMoreEntities(BaseQueryResultsSource.java:164)
    at com.google.appengine.api.datastore.QueryResultIteratorImpl.ensureLoaded(QueryResultIteratorImpl.java:147)
    at com.google.appengine.api.datastore.QueryResultIteratorImpl.hasNext(QueryResultIteratorImpl.java:64)
    at com.googlecode.objectify.impl.KeysOnlyIterator.hasNext(KeysOnlyIterator.java:29)
    at com.googlecode.objectify.impl.ChunkIterator.next(ChunkIterator.java:48)
    at com.googlecode.objectify.impl.ChunkIterator.next(ChunkIterator.java:20)
    at com.google.common.collect.Iterators$5.hasNext(Iterators.java:543)
    at com.google.common.collect.Iterators$PeekingImpl.hasNext(Iterators.java:1139)
    at com.googlecode.objectify.impl.ChunkingIterator.hasNext(ChunkingIterator.java:51)
    at com.google.common.collect.Iterators.addAll(Iterators.java:356)
    at com.google.common.collect.Lists.newArrayList(Lists.java:146)
    at com.google.common.collect.Lists.newArrayList(Lists.java:128)
    at com.googlecode.objectify.util.MakeListResult.translate(MakeListResult.java:21)
    at com.googlecode.objectify.util.MakeListResult.translate(MakeListResult.java:11)
    at com.googlecode.objectify.util.ResultTranslator.nowUncached(ResultTranslator.java:21)
    at com.googlecode.objectify.util.ResultCache.now(ResultCache.java:30)
    at com.googlecode.objectify.util.ResultProxy.invoke(ResultProxy.java:32)
    at com.sun.proxy.$Proxy45.size(Unknown Source)
    at io.divide.dao.appengine.ObjectifyDAO.query(ObjectifyDAO.java:64)
    at io.divide.server.dao.DAOManager.query(DAOManager.java:62)
    at io.divide.server.endpoints.DataEndpoint.query(DataEndpoint.java:69)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:45)
    at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:151)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:171)
    at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:104)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:406)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:350)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:106)
    at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:259)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:319)
    at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:236)
    at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1028)
    at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:373)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:219)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:438)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:445)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:220)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:309)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:301)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:442)
    at java.lang.Thread.run(Thread.java:724)

The identical query works in an app engine dev server.

6thSigma commented 9 years ago

I added Automatic index configuration to the App Engine sample code.

If you then run all queries in the dev server and then run the following:

mvn appengine:update_indexes

Indexes will automatically be updated for your production server and the queries will work.

Ideally we'd like this to be automatically generated for our users without having to run all queries in the dev server. We'll continue looking into this.