2

I have the error:

BadRequestError: app "dev~myapp" cannot access app "s~myapp"'s data

Which is similar, but the opposite way around to this question.

The answer doesn't seem to apply to my app though (even trying to turn it on its head) - I have only one app, and I am not using the remote API, and I am not using urlsafe keys, and all my key properties are db.ReferencePropertys, or db.ListProperty( db.Key )s.

The error comes in the first line of the template I attempt to render:

File "/.../template.html", line 1, in top-level template code {% extends "page.html" %}

If I comment out that line, then the error occurs:

File "/.../template.html", line 1, in top-level template code <!--{% extends "page.html" %}-->

Which suggested to me that the error is in actually loading the template with Jinja, prior to applying template magic.

template.html is rendered with variables that are entity lists (not Query objects, but [e for e in queryObject]s). If I replace these with an empty list, the page renders fine.

My dev server's datastore is populated with a backup from the production server, but I have not had a problem accessing these entries until now. I am getting these entity lists as follows:

@staticmethod
def gql(query, *a, **kw):
    keys    = super(Model, Model).gql(query, *a, **kw).run(keys_only=True)
    cached  = []

    for key in keys:
        inCache = memcache.get('Model_'+str(key))
        if inCache:
            cached.append(inCache)
        else:
            fromDB = Model.get(key)
            memcache.set('Model_'+str(key), fromDB)
            cached.append( fromDB )

    return cached

I can print the results out with logging prior to rendering with Jinja fine. It's also fine in the interactive console.

Why does this become an attempt to access another app's data, and raise this exception when Jinja renders it?

Community
  • 1
  • 1
OJFord
  • 10,522
  • 8
  • 64
  • 98

2 Answers2

3

I found the cause - db.ListProperty( db.Key )s have the form:

[datastore_types.Key.from_path(u'ModelName', IDnumL, _app=u's~myapp')]

This is as imported to dev server from a production server backup using this neat function on gist.

Unfortunately, as I have grumbled about before, the dev server does not allow editing of db.ListPropertys (and a couple of other types).

My solution was to perform the following in the interactive console:

from google.appengine.ext.db import Key

for e in Model.all():
    if e.keyList:
        prod = e.keyList
        dev  = eval( str(prod).replace('s~','dev~').replace('datastore_types.','') )
        e.keyList = dev
        e.put()
OJFord
  • 10,522
  • 8
  • 64
  • 98
0

This occurred to me after restarting my computer. The appserver produced the same error because it could not connect to my datastore emulator's local_db.bin. The datastore emulator when started also returns a

SEVERE: Failed to find the backing store, /path/.config/gcloud/emulators/datastore/WEB-INF/appengine-generated/local_db.bin

So I renamed the local_db.bin and rerun the emulator and dev_appserver.

Warning: removes all your previous data

In my case I had a seeder file and just rerun it.

Rad Apdal
  • 442
  • 1
  • 6
  • 16