Application x1 cannot access application data x2

I copied some namespace data from x1 to x2 using a remote api and a low-level api data store.

I refer to the x2 application to get the following error for some data

  java.lang.IllegalArgumentException: app x1 cannot access app x2 data
     at com.google.appengine.api.datastore.DatastoreApiHelper.translateError (DatastoreApiHelper.java:36)
     at com.google.appengine.api.datastore.DatastoreApiHelper $ 1.convertException (DatastoreApiHelper.java:76)
     at com.google.appengine.api.utils.FutureWrapper.get (FutureWrapper.java:106)
     at com.google.appengine.api.datastore.FutureHelper $ CumulativeAggregateFuture.get (FutureHelper.java:145)
+4
source share
2 answers

As stated in this post: Migration to HRD - How to convert string encodings to a new application, all entity keys contain a link to app-id. If you use keys encoded as String, this link will not be updated when copying data to a new application. But you can do it yourself.

Just run the query in the new environment to update each individual key to point to a new application identifier. In this example, I assume that each object implements this interface:

Interface Entity{ public Key getKey(); public void setKey(Key key); } 

Now I can use this method:

 //... List<Entity> entities = //... your query for (Entity entity : entities){ entity.setKey(generateNewKey(entity.getKey()); } //... //Method written by Nikolay Ivanov in the other post, that recursive generate a new key respecting to parents private Key generateNewKey(Key key) { Key parentKey = key.getParent(); if(parentKey == null){ return KeyFactory.createKey(key.getKind(), key.getId()); }else{ Key newParentKey = generateKey(parentKey); return KeyFactory.createKey(newParentKey, key.getKind(), key.getId()); } } 
+1
source

You need to fix the keys so that they have the correct application identifier.

Here's a bit of Python I'm using:

  key = db.Key(k) if key.app() == appname: return db.get(key) logging.info("Fixing up key from old app %s (%s=%s)" % ( key.app() , key_attr , k )) fixed_key = db.Key.from_path(*key.to_path()) 
0
source

Source: https://habr.com/ru/post/1400782/


All Articles