2017-05-17 16 views
1

私はGoogle App Engineにプロジェクトをデプロイしました....私はロールバックの問題に直面しています。私は、メソッドの戻りまたは終了の前にコミットするRelational dbのようにロールバックする必要があります。私たちはこれをndbでどのように達成するのですか?メソッドが失敗した後にGoogle App Engine NDBでロールバックする方法

どのように私はロールバックします、私の機能だけで復帰する前と第二プットの後に失敗したと仮定???明快

class PersonTable(ndb.Model): 
    personId = ndb.StringProperty() 
    personName = ndb.StringProperty() 
    personAddress = ndb.StringProperty() 
    personOldReference = ndb.StringProperty() 
    scopeReference = ndb.StringProperty()  

class ScopeTable(ndb.Model): 
    child = ndb.StringProperty() 
    isPerson = ndb.BooleanProperty() 
    parent = ndb.StringProperty() 

@endpoints.method(ZGScopeRequest, ZGScopeResponse, name='scope', path='scope', http_method='POST') 
def scope(self, request): 

    scope = request.scope 
    person = request.personName 
    list = scope.split('.') 
    length = len(list) 
    for entry in list: 
     newId = GenerateRandomId('SCOPE') 
     child = mobileappmodels.ScopeTable.query(mobileappmodels.ScopeTable.child.IN([entry])).get() 
     if child: 
      pass 
     else: 
      index = list.index(entry) 
      parent = list[index-1] 
      if entry == 'PersonName': 
       entry = person 
       fetchPerson = mobileappmodels.CommunityTable.gql("""WHERE personName = :1""",entry).fetch() 
       update = fetchCommunity[0].key.get() 

       update.scopeReference = newId 
       update.put() 

       save = mobileappmodels.ScopeTable(child=person, isCommunity = True, parent = parent, id=newId) 
       save.put() 

      elif entry == 'Global': 
       save = mobileappmodels.ScopeTable(child=entry, isCommunity = False, parent = '', id=newId) 
       save.put() 
      else: 
       save = mobileappmodels.ScopeTable(child=entry, isCommunity = False, parent = parent, id=newId) 
       save.put() 

    return ZGScopeResponse(message="Uploaded") 

のためのコードスニペットの下に見つけてください。私は

答えて

0

は必ず私が理解していないGoogleのApp EngineとNDBに新しいですと

ヘルプは本当に感謝されるだろう。最後に入れて帰ってからどうしたら失敗するのですか?

おそらくあなたは、トランザクション内のコードを実行したい:

https://cloud.google.com/appengine/docs/standard/python/ndb/transactions

あなたが取引でそれを実行し、必要に応じてndb.Rollbackを呼び出すことができます。

+0

あなたは正しいと思いますが、戻ってくる前と後ろにはどうして失敗するのですか...技術的には失敗しないでしょう。 –

+0

トランザクションを使用しようとしましたが、次のエラーが返されていますBadRequestError:トランザクション内で祖先クエリのみが許可されています。 –

関連する問題