John John - 1 year ago 80
Python Question

Why does key = model_instance.key have No!!! next to it in the db to ndb docs?

Previously I was using db instead of ndb. Now I'm migrating my code. The db.model equivalent of

key = model_instance.key()


key= model_instance.key

which has a No !!! next to it. But it doesn't say what we should use instead.

How would I write in ndb? And why is this not good?


Answer Source

I presume you're referring to the NDB Cheat Sheet, more specifically to the 4th row in the Entities table:

key = model_instance.key()  |   key = model_instance.key  # no () !!

The text is actually # no () !!, meaning no parenthesis/not a function call. Which is correct in the context as that's the method of obtaining the entity's key, which is an attribute in ndb, vs. a function call in db. It doesn't mean "do not use".