Testing locally with Objectify 6 - Permission denied on resource project no_app_id

486 views
Skip to first unread message

H Singh

unread,
Jun 29, 2022, 1:03:57 PM6/29/22
to objectify-appengine
I've migrated my code from Objectify 5 to 6. It seems to be working fine in production, but I'm not able to test it locally. 

I get this exception:

com.google.datastore.v1.client.DatastoreException: Permission denied on resource project no_app_id., code=PERMISSION_DENIED

I have done "gcloud auth application-default login" and it generated the application default credentials. Before I did the authentication, I was getting the following exception:

com.google.datastore.v1.client.DatastoreException: Unauthenticated., code=UNAUTHENTICATED

Why do I need to do authentication when I'm running the app locally? How do I fix the Permission Denied issue? 

Thanks!


Jeff Schnitzer

unread,
Jun 29, 2022, 4:36:58 PM6/29/22
to objectify-appengine
When you say test it locally - do you mean running against the datastore emulator? Do you have the environment variables set up as described here?


Jeff

--
You received this message because you are subscribed to the Google Groups "objectify-appengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to objectify-appen...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/objectify-appengine/d8477181-0d7f-4e33-ba8b-9da394ffa310n%40googlegroups.com.

H Singh

unread,
Jun 30, 2022, 9:30:04 AM6/30/22
to objectify-appengine
Thank you so much, Jeff. 

I'm not sure how I did not come across this despite going through so much documentation. It maybe just me, but I find that GCP documentation is all over the place. 

Now after setting up everything, I'm able to run the datastore emulator, but I get the following exception when starting my app server on local:

GCLOUD: MultiException[java.lang.IllegalArgumentException: Unable to construct RemoteRpc due to unsupported url: <http://::1:8038/v1/projects/myproject>, java.lang.ExceptionInInitializerError, java.lang.ExceptionInInitializerError]

I used the automatic approach of setting the environment variables for the emulator i.e. using `$(gcloud beta emulators datastore env-init)`. 

After this I was getting another error, which is mentioned in this post: https://stackoverflow.com/questions/45659186/illegalstateexception-with-google-app-engine-local-datastoreI resolved it by using the solution mentioned in that post. Now I'm stuck with the unsupported url error. 

Any idea on how to address it? 

Thanks!

H Singh

unread,
Jun 30, 2022, 11:28:26 AM6/30/22
to objectify-appengine
I was able to get past that error by manually setting the env vars and replacing ::1 with localhost. But now I'm getting an I/O error from objectify library when calling iterator(). Here's the stack trace:

[INFO] GCLOUD: com.google.cloud.datastore.DatastoreException: I/O error
[INFO] GCLOUD:  at com.google.cloud.datastore.spi.v1.HttpDatastoreRpc.translate(HttpDatastoreRpc.java:128)
[INFO] GCLOUD:  at com.google.cloud.datastore.spi.v1.HttpDatastoreRpc.translate(HttpDatastoreRpc.java:113)
[INFO] GCLOUD:  at com.google.cloud.datastore.spi.v1.HttpDatastoreRpc.runQuery(HttpDatastoreRpc.java:181)
[INFO] GCLOUD:  at com.google.cloud.datastore.DatastoreImpl$1.call(DatastoreImpl.java:180)
[INFO] GCLOUD:  at com.google.cloud.datastore.DatastoreImpl$1.call(DatastoreImpl.java:177)
[INFO] GCLOUD:  at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:105)
[INFO] GCLOUD:  at com.google.cloud.RetryHelper.run(RetryHelper.java:76)
[INFO] GCLOUD:  at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:50)
[INFO] GCLOUD:  at com.google.cloud.datastore.DatastoreImpl.runQuery(DatastoreImpl.java:176)
[INFO] GCLOUD:  at com.google.cloud.datastore.QueryResultsImpl.sendRequest(QueryResultsImpl.java:73)
[INFO] GCLOUD:  at com.google.cloud.datastore.QueryResultsImpl.<init>(QueryResultsImpl.java:57)
[INFO] GCLOUD:  at com.google.cloud.datastore.DatastoreImpl.run(DatastoreImpl.java:170)
[INFO] GCLOUD:  at com.google.cloud.datastore.DatastoreImpl.run(DatastoreImpl.java:161)
[INFO] GCLOUD:  at com.googlecode.objectify.impl.AsyncDatastoreReaderWriterImpl.run(AsyncDatastoreReaderWriterImpl.java:60)
[INFO] GCLOUD:  at com.googlecode.objectify.impl.QueryEngine.queryNormal(QueryEngine.java:58)
[INFO] GCLOUD:  at com.googlecode.objectify.impl.QueryImpl.iterator(QueryImpl.java:308)
[INFO] GCLOUD:  at com.googlecode.objectify.cmd.QueryResultIterable.iterator(QueryResultIterable.java:11)

Am I missing something here?

Thanks!

H Singh

unread,
Jun 30, 2022, 12:01:39 PM6/30/22
to objectify-appengine
Finally, I managed to resolve this. Instead of replacing ::1 with localhost, I had to put square brackets around it. This is what my env vars look like now: 

DATASTORE_DATASET=my-project-id
DATASTORE_EMULATOR_HOST=[::1]:8630
DATASTORE_EMULATOR_HOST_PATH=[::1]:8630/datastore
DATASTORE_HOST=http://[::1]:8630
DATASTORE_PROJECT_ID=my-project-id
DATASTORE_USE_PROJECT_ID_AS_APP_ID=true

As an additional note, I'm using https://github.com/GabiAxel/google-cloud-gui for datastore emulator admin UI. 

Jeff - Thanks for the wonderful work with the Objectify project. I really appreciate it. 

Jeff Schnitzer

unread,
Jun 30, 2022, 12:35:48 PM6/30/22
to objectify-appengine
That's good to know! Seems to be a recent macos thing.

And I agree with you about the GCP docs. Part of it I guess is just that GCP now has such a huge footprint. But also, there doesn't seem to be any coherent "how it all fits together" the way there used to be for appengine. Everything is a la carte, including the documentation.

Jeff

Reply all
Reply to author
Forward
0 new messages