Google app engine Google应用程序引擎-将现有NDB属性升级为重复的结构化属性

Google app engine Google应用程序引擎-将现有NDB属性升级为重复的结构化属性,google-app-engine,google-cloud-datastore,app-engine-ndb,Google App Engine,Google Cloud Datastore,App Engine Ndb,我有一个在GAE中运行的生产应用程序,NDB中有大量数据 在我的一个模型中,我有一个从未使用过的属性,但为了“未来验证”而添加了超过2年,问题是该属性的声明如下: notes = ndb.TextProperty() class Note(Model): created_by = ndb.StringProperty() text = ndb.TextProperty() notes = ndb.StructuredProperty(Note, repeated=True,

我有一个在GAE中运行的生产应用程序,NDB中有大量数据

在我的一个模型中,我有一个从未使用过的属性,但为了“未来验证”而添加了超过2年,问题是该属性的声明如下:

notes = ndb.TextProperty()
class Note(Model):
    created_by = ndb.StringProperty()
    text = ndb.TextProperty()
notes = ndb.StructuredProperty(Note, repeated=True, default=[])
因此,我当前的所有模型都有“notes:None”,因为它们从未填充过

我现在想将其更改为重复的结构化属性,如下所示:

notes = ndb.TextProperty()
class Note(Model):
    created_by = ndb.StringProperty()
    text = ndb.TextProperty()
notes = ndb.StructuredProperty(Note, repeated=True, default=[])

进行此更改时,我收到以下错误:

RuntimeError:StructuredProperty注释应找到属性 由深度为1的周期分隔;已收到[“通知”]

这是有道理的,主要问题是我正在将其从none repeated属性更改为repeated属性(如果我将其更改为模型'Note'的单个实例,则不会出现错误,因为none可以传递到none repeated属性)

我真的不想做一个新的参数,因为名字注释是完美的。。。 到目前为止,我找到的最佳解决方案是:

然而,鉴于我在该属性中没有任何有效数据,我不得不迁移+-900000个实体以删除一个没有数据的字段,这似乎是一笔巨大的开销

我甚至考虑过在“platform/google\u appengine/google/appengine/ext/ndb/model.py”中扩展_反序列化方法,因为我可以看到它在哪里抛出异常,因为它的值是None而不是[],但是这似乎不是一个好主意,或者谷歌会建议我做的事情

我心目中的圣杯是这样的:

notes = ndb.TextProperty()
class Note(Model):
    created_by = ndb.StringProperty()
    text = ndb.TextProperty()
notes = ndb.StructuredProperty(Note, repeated=True, default=[])

这将使此属性设置为默认值,即_反序列化失败时的[],而不是抛出500并终止我的应用程序


谢谢

您有两个选项,可以围绕便笺创建一个包装器对象,如:

notes = ndb.StructuredProperty(Notes)

class Notes(ndb.Model):
  notes = ndb.StructuredProperty(Note, repeated=True)
您还可以在数据存储中使用不同的名称,例如

notes = ndb.StructuredProperty(Note, name='real_notes', repeated=True)

我认为唯一的解决办法是重写900000个实体或使用不同的属性名称。谢谢,ye,这就是我担心的。。。这是我在迁移所有文档之前的最后一个希望,我也将此查询升级到GAE,因此如果我从他们那里得到任何信息,我会将其添加到这里。感谢名称解决方案非常适合我们需要做的事情!