- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
虽然 NDB 文档说:
Although a StructuredProperty can be repeated and a StructuredProperty can contain another StructuredProperty, beware: if one structured property contains another, only one of them can be repeated.
在我看来,文档最清晰的解释可以正确地写为“如果一个结构化属性包含另一个结构化属性”。
在这种情况下,我希望这样的事情能够起作用:
class KeyList(ndb.Model):
keys = ndb.KeyProperty(repeated=True)
class Collection(ndb.Model):
lists = ndb.StructuredProperty(KeyList, repeated=True)
但是,此操作失败并出现错误:
TypeError: This StructuredProperty cannot use repeated=True because its model class (KeyList) contains repeated properties (directly or indirectly).
似乎无法在重复的 StructuredProperty 中嵌套任何重复属性。
从代码来看,这个looks to be the intended behaviour .
在这种情况下,开发应用程序服务器可能与记录的行为不同。如果我读到的文档是正确的,那么修复 the condition in the development server giving rise to the above error可能是这样的:
if modelclass._has_repeated and isinstance(modelclass, StructuredProperty):
# ...
AppEngine StructuredProperty 是否应该能够包含重复属性(重复的 StructuredProperty 除外)?
问题报告在这里:https://github.com/GoogleCloudPlatform/appengine-python-vm-runtime/issues/40
编辑值得注意的是 golang docs说这个:
Slices of structs are valid, as are structs that contain slices. However, if one struct contains another, then at most one of those can be repeated. This disqualifies recursively defined struct types: any struct T that (directly or indirectly) contains a []T.
我从中得到的含义是,重复结构上的重复非结构属性在 BigTable 级别并不是本质上被禁止的,而是 Python 实现的副作用。
如果没有进一步的证实,我不会依赖这个暗示。
最佳答案
这是我们文档中的一个错误 --
使用StructuredProperty
,您只能拥有单层重复属性。
一些背景:
ndb 通过在写入数据存储区之前分解属性来处理 StructuredProperty
。例如:
class Inner(ndb.Model):
a = ndb.StringProperty()
class Outer(ndb.Model):
inner = ndb.StructuredProperty(Inner, repeated=True)
然后,如果我们编写:Outer(inner=[Inner(a="1"), Inner(a="2")])
,这实际上会写入数据存储区:
{
inner.a = ["1", "2"]
}
但是,如果重复Inner.a
,我们可以编写如下内容:
Outer(inner=[Inner(a=["1", "3"]), Inner(a=["2", "4"])])
这将被写入数据存储,如下所示:
{
inner.a : ["1", "3", "2", "4"]
}
然后当我们读到这个时,我们不知道如何解析,因为所有这些都是有效的:
Outer(inner=[Inner(a=["1", "3"]), Inner(a=["2", "4"])])
Outer(inner=[Inner(a=["1", "3", "2"]), Inner(a=["4"])])
Outer(inner=[Inner(a=["1"]), Inner(a=["3"]), Inner(a=["2"]), Inner(a=["4"])])
Outer(inner=[Inner(a=[]), Inner(a=["1", "3", "2", "4"])])
请注意,其他库(例如 Objectify)可以通过存储用于索引的分解属性和整个数据集的未索引 blob(可以维护反序列化结构)来避免此问题。
关于python - StructuredProperty 的重复嵌套属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34790724/
我有一个实体,其中有一个可变数量的另一个实体(所以我使用结构化属性,repeated=True),但是一个属性也可以容纳可变数量的单一实体类型。所以我的代码看起来像这样: class Property
虽然 NDB 文档说: Although a StructuredProperty can be repeated and a StructuredProperty can contain anoth
我的模型都有一个将模型转换为字典的方法: def to_dict(model): output = {} SIMPLE_TYPES = (int, long, float, bool,
StructuredProperty 是否引用父级或子级? class Invoices(ndb.Model): #Child class Customers(ndb.Model): #Parent
StructuredProperty 上没有 populate 方法(如 ndb.Model 上的方法),那么如何从字典中填充这些字段? 最佳答案 您仍然可以填充StructuredProperty。
我读过很多关于这两者的文章 ndb.StructuredProperty在 App Engine 的 NDB 中以及 ancestor queries 的使用将相关实体分组在一起。 但是,我不确定我是
我想将位置存储在 Google 的数据存储区中。每个条目应具有“sys”字段,其中应包含数据存储设置的信息。我有下面的类模型,并且 WebService JSON 请求/响应看起来不错,但我必须手动设
在一个汽车历史应用程序中,我必须创建不同的图表,其中某些车型可能会出现在一个或多个不同的图表中,如“最快的汽车”、“最好的汽车”等。然后必须在图表中对它们进行排序。我使用 StructuredProp
这里是 StructuredProperty from the docs 的示例: class Address(ndb.Model): type = ndb.StringProperty()
我有一个 HUser 模型(派生自 Google 的 User 类),它又包含 0 到 n 个社交帐户实例。这些帐户可以是对 Facebook、Twitter 或 LinkedIn 帐户的引用。我已经
假设我有一个 ndb.Model 类,我想将其用作另一个模型类的 StructuredProperty: class CommonExtraData(ndb.Model): count = n
这是我的ndb模型 from google.appengine.ext import ndb from mainsite.rainbow.models.CFCSocialUser import CFC
使用appengine mapreduce lib时,如何通过StructuredProperty进行过滤? 我尝试过: class Tag(ndb.Model): # ... tag
我正在尝试使用 Expando模型作为重复 StructuredProperty在另一个模型中。即,我想添加不定数量的Accounts给我的User模型。如Accounts根据其类型可以具有不同的属性
我使用 Google App Engine 进行后端开发,并使用数据存储模型和 Google Cloud Storage 来存储图像对象。这是我的媒体模型 class Media(ndb.Model)
我有一个 ndb.Model,其中包含一个 Repeated 属性。 class Resort(ndb.Model): name = ndb.StringProperty()
大家好,我正在尝试弄清楚如何针对以下情况构造我的查询 首先我定义了一个模型 class Variant(ndb.Expando): test = ndb.StringProperty() cl
大家好,我正在尝试弄清楚如何针对以下情况构造我的查询 首先我定义了一个模型 class Variant(ndb.Expando): test = ndb.StringProperty() cl
我是一名优秀的程序员,十分优秀!