dev_appserver.py BadArgumentError: app must not be empty
Asked Answered
A

2

6

Hey all,

For context: I had this dev_appserver setup working late last year in 2021, and upon trying to set it up again, I'm getting odd errors. BadArgumentError: app must not be empty.

I've solved quite a lot of errors up to this point, and this is where I'm at:

  • JDK 1.11+ installed (for Cloud Datastore Emulator)
  • Golang 1.15+ installed (for gops & dev_appserver.py - go build)
  • Gcloud Components:gcloud components

I run my dev_appserver like this:

export DATASTORE_DATASET=dev8celbux
export DATASTORE_PROJECT_ID=dev8celbux
export DATASTORE_USE_PROJECT_ID_AS_APP_ID=true
dev_appserver.py --enable_console --admin_port=8001 --port=8081 --go_debugging=true --support_datastore_emulator=true --datastore_path=./datastore/local_db.bin setuptables-app.yaml

INFO     2022-09-09 13:26:30,233 devappserver2.py:317] Skipping SDK update check.
INFO     2022-09-09 13:26:30,250 datastore_emulator.py:156] Starting Cloud Datastore emulator at: http://localhost:58946
INFO     2022-09-09 13:26:32,381 datastore_emulator.py:162] Cloud Datastore emulator responded after 2.131000 seconds
INFO     2022-09-09 13:26:32,381 <string>:384] Starting API server at: http://localhost:59078
INFO     2022-09-09 13:26:32,384 <string>:374] Starting gRPC API server at: http://localhost:59079
INFO     2022-09-09 13:26:32,394 instance_factory.py:184] Building with dependencies from go.mod.
INFO     2022-09-09 13:26:32,397 dispatcher.py:280] Starting module "setuptables" running at: http://localhost:8081
INFO     2022-09-09 13:26:32,397 admin_server.py:70] Starting admin server at: http://localhost:8001
WARNING  2022-09-09 13:26:32,398 devappserver2.py:414] No default module found. Ignoring.
2022/09/09 13:26:35 STARTING
INFO     2022-09-09 13:26:37,220 instance.py:294] Instance PID: 9656

This error appears when I try & view the contents within the local datastore at localhost:8001/datastore.

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2\webapp2\__init__.py", line 1526, in __call__
    rv = self.handle_exception(request, response, e)
  File "C:\Users\user\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2\webapp2\__init__.py", line 1520, in __call__
    rv = self.router.dispatch(request, response)
  File "C:\Users\user\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2\webapp2\__init__.py", line 1270, in default_dispatcher
    return route.handler_adapter(request, response)
  File "C:\Users\user\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2\webapp2\__init__.py", line 1094, in __call__
    return handler.dispatch()
  File "C:\Users\user\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\admin\admin_request_handler.py", line 88, in dispatch
    super(AdminRequestHandler, self).dispatch()
  File "C:\Users\user\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2\webapp2\__init__.py", line 588, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "C:\Users\user\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2\webapp2\__init__.py", line 586, in dispatch
    return method(*args, **kwargs)
  File "C:\Users\user\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\admin\datastore_viewer.py", line 661, in get
    kinds = self._get_kinds(namespace)
  File "C:\Users\user\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\admin\datastore_viewer.py", line 597, in _get_kinds
    return sorted([x.kind_name for x in q.run()])
  File "C:\Users\user\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\db\__init__.py", line 2077, in run
    raw_query = self._get_query()
  File "C:\Users\user\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\db\__init__.py", line 2482, in _get_query
    _app=self._app)
  File "C:\Users\user\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\api\datastore.py", line 1371, in __init__
    self.__app = datastore_types.ResolveAppId(_app)
  File "C:\Users\user\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\api\datastore_types.py", line 238, in ResolveAppId
    ValidateString(app, 'app', datastore_errors.BadArgumentError)
  File "C:\Users\user\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\api\datastore_types.py", line 186, in ValidateString
    raise exception('%s must not be empty.' % name)
BadArgumentError: app must not be empty.

I figured out that it is somewhat related to the APPLICATION_ID environment variable being missing. Upon setting it, I am able to view the Database page. HOWEVER. When getting no errors writing my data to the emulator (line by line debugged to confirm & local_db.bin is created), upon looking at the data, nothing is there. I successfully write 15 entities from the code's point of view. However none appear on the admin page. I think it's due to the manual set of the APPLICATION_ID as I did not do this before. Perhaps should be automatic somehow. Was thinking that this environment variable could maybe do that: export DATASTORE_USE_PROJECT_ID_AS_APP_ID=true but doesn't seem to change anything.

Before calling creation of entities:

before

After calling creation of entities:

after

I write the data like this, no doubt this works correctly.

ctx, err := appengine.Namespace(appengine.BackgroundContext(), "celbux101")
...
userKeyOut, err := datastore.Put(ctx, userKey, &F1_4{...})

Also, looked in both the default & the designated namespace (celbux101):

celbux101

empty

Super stumped. :( Help appreciated!

I really think it may somehow be related to APPLICATION_ID

Altaf answered 9/9, 2022 at 11:45 Comment(1)
I had some similar issues with you (My app uses Python3 runtime anyhow). Per my understanding, your setup is working on top of dev_appserver's embedded datastore emulator, but not the the gloud standalone emulator (the one invoked by "gcloud beta emulators datastore start"). You started the standalone emulator, but it is doing nothing. To verify that you could check the output of the gcloud emulator console. Everytime you read/write data to it, you should see some log message like "io.gapi.emulators.netty.HttpVersionRoutingHandler". If nothing shows up, it is not connected to your application.Coricoriaceous
A
17

Yes!

... I managed to come to a solution! As suspected, the data was getting written correctly, as confirmed by the line-by-line debug & the creation of the local_db.bin. The issue is that the dev_appserver's UI is not able to show the database entities due to the incorrect or missing APPLICATION_ID, as deducted.

I figured out that the dev_appserver's UI uses both the APPLICATION_ID & namespace to determine where to look for your entities. Also, the dev_appserver has it's own default APPLICATION_ID.

Solution

The fix is to export this environment variable BEFORE running your dev_appserver.py.

export APPLICATION_ID=dev~None

This magic export allows everything work as expected. You can view the APPLICATION_ID that the UI is trying to use on the top-left of the interface.

EDIT: I just came back to running this on a new computer, and want to add this for future reference:

If you are getting IOError: emulator did not respond within 10s

INSTALL Python27 & add to your path! (alongside your bundled python)

enter image description here

Altaf answered 10/9, 2022 at 13:7 Comment(0)
S
2

python2 gcloud 451.0.1 (2023) and development server. None (with capital N) does not work anymore (gives a regex validation error).

export APPLICATION_ID=dev~XXXXXXXXX
dev_appserver.py --application=XXXXXXXXX --storage_path=var --datastore_path=var/data.store --blobstore_path=var/blob.store app

Where XXXXXXXXX is:

  1. application: project-id # from the app.yaml file
  2. dev_appserver.py --application=project-id # or -A

python3 behaves differently:

  1. Removing export APPLICATION_ID but keeping --application=project-id results in a BadArgumentError: app must not be empty by datastore.py
  2. export APPLICATION_ID=dev~None and dev_appserver.py --application=project-id results in BadRequestError: app "dev~XXXXXXXX" cannot access app "dev~None"'s data
Selfsupporting answered 22/10, 2023 at 21:18 Comment(1)
For those who are using powershell, export statement is: $env:APPLICATION_ID="dev~XXXXXXXXX"Parnassian

© 2022 - 2024 — McMap. All rights reserved.