Matt Norris Matt Norris - 17 days ago 5
Python Question

Does db.run_in_transaction return anything?

I'm mimicking a transaction example I found in the Taggable Mixin, but it's not behaving in the same manner.

def txn():
// statements omitted for brevity
blog_index.put()
new_post = Post(key_name=new_post_key_name, parent=blog_index,
index = new_index, title = new_title,
body = new_body)
new_post.put()
return new_post

def new_post(cls, new_title=None, new_body=None, new_tags=[]):
new_post = db.run_in_transaction(txn)

new_post.tags = new_tags
new_post.put()


In this example, the
new_post
from
txn
is returned through
db.run_in_transaction
, then something can be done with it. But I am getting:

TypeError: object is not callable


This leads me to believe the function
run_in_transaction
is getting assigned to the
new_post
variable, not the actual
new_post
returned from
txn
.

Can
db.run_in_transaction
return anything, like the values from the callable function?

Answer

run_in_transaction returns whatever the called function returned. You need to include the compelte stacktrace and the original code for us to help.

Comments