Get_by_id () does not return a model instance

I have a model called Version that looks like this:

from google.appengine.ext import db
import piece

class Version(db.Model):
    "A particular version of a piece of writing."

    parent_piece = db.ReferenceProperty(piece.Piece, collection_name='versions')
    "The Piece to which this version belongs."

    note = db.TextProperty()
    "A note from the Author about this version."

    content = db.TextProperty()
    "The actual content of this version of the Piece."

    published_on = db.DateProperty(auto_now_add=True)
    "The date on which the version was published."

I would like to access Version instances through their identifiers using Version.get_by_id (), but this call always returns None. I see in the Datastore Viewer that they have ID values, and in the debugger I can request them, but not use them:

>>> for each_ver in version.Version.all():
...  print each_ver.key().id()
... 
34
35
36
31
32
>>> a = version.Version.get_by_id(34)
>>> type(a)
<type 'NoneType'>

I see that there are many questions where people can use get_by_id () effectively as I wish, and they don’t see the results that I see.

, Entity, Entity Group? Entity, Member- > Piece- > Version. , , Version ? , - , , get_by_id() ?

+3
2

, instance - Entity Entity?

. .

, , ?

. , . , db.Key.from_path .

+6

, ndb.Model, , ID int. version.Version.get_by_id(int(34)) .

0

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


All Articles