google 云数据存储实体对象上的 AttributeError
AttributeError on google cloud datastore entity object
我有一个名为作者的实体。下面是ndb class:
class Author(ndb.Model):
name = ndb.StringProperty()
website = ndb.StringProperty()
bio = ndb.StringProperty()
profile_image_url = ndb.StringProperty()
slug = ndb.ComputedProperty(lambda self: make_slug(self.name))
我正在创建这样的作者对象
author = Author(id=pk, **author_dict)
author.put()
第一次创建author对象没有报错
我正在检索这样的作者对象
author = Author.get_by_id(pk)
当我尝试访问作者简介字段时,我得到一个 AttributeError
author.bio = bio_text
访问现有作者对象上的字段时出现错误。并非所有字段都出现错误。
控制台正在显示所有列。 bio 列存在于作者实体的数据存储控制台中。
我删除了所有作者实体并创建了新条目。我仍然收到 AttributeError。
我在数据存储中有多个实体,但我只收到作者实体的错误。
错误陈述:
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py",
line 2990, in _set_attributes
prop = getattr(cls, name) # Raises AttributeError for unknown properties.
AttributeError: type object 'Author' has no attribute 'bio'
关闭:
我在另一个模块中有一个名为 Author 的 class。 NDB 以某种方式使用此 class 创建作者实体并导致此行为。
我在另一个模块中有一个名为 Author 的 class。此 class 在另一个实体 class 中用作结构化 属性。
不知何故,这个 class 被 NDB 用来创建作者实体。我将其重命名为 class,错误消失了。
现在我为所有 ndb 实体和结构化属性使用不同的 class 名称。
我有一个名为作者的实体。下面是ndb class:
class Author(ndb.Model):
name = ndb.StringProperty()
website = ndb.StringProperty()
bio = ndb.StringProperty()
profile_image_url = ndb.StringProperty()
slug = ndb.ComputedProperty(lambda self: make_slug(self.name))
我正在创建这样的作者对象
author = Author(id=pk, **author_dict)
author.put()
第一次创建author对象没有报错
我正在检索这样的作者对象
author = Author.get_by_id(pk)
当我尝试访问作者简介字段时,我得到一个 AttributeError
author.bio = bio_text
访问现有作者对象上的字段时出现错误。并非所有字段都出现错误。
控制台正在显示所有列。 bio 列存在于作者实体的数据存储控制台中。
我删除了所有作者实体并创建了新条目。我仍然收到 AttributeError。
我在数据存储中有多个实体,但我只收到作者实体的错误。
错误陈述:
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py",
line 2990, in _set_attributes
prop = getattr(cls, name) # Raises AttributeError for unknown properties.
AttributeError: type object 'Author' has no attribute 'bio'
关闭:
我在另一个模块中有一个名为 Author 的 class。 NDB 以某种方式使用此 class 创建作者实体并导致此行为。
我在另一个模块中有一个名为 Author 的 class。此 class 在另一个实体 class 中用作结构化 属性。
不知何故,这个 class 被 NDB 用来创建作者实体。我将其重命名为 class,错误消失了。
现在我为所有 ndb 实体和结构化属性使用不同的 class 名称。