1

我的问题:

我正在尝试使用“POST”请求在 GAE 中填充包含 ndb.Structured Property() 的数据存储模型。

最近有人问过这个问题但没有回答(如何“发布”ndb.StructuredProperty?

我有以下两个模型:

class Check(EndpointsModel):
    this = ndb.StringProperty()
    that = ndb.StringProperty()

class CheckMessage(EndpointsModel):
    check = ndb.StructuredProperty(Check)

我正在尝试发布这些数据:

{
    check:
    {
        "this":"test",
        "that":"test"
    }
}

使用以下 API 请求:

@CheckMessage.method(name='check_insert',path='check/insert',http_method='POST')
    def check_insert(self,request):
        print(request)

从客户发帖后,我收到以下错误:

AttributeError: 'Check' object has no attribute '_Message__decoded_fields'

问题:

从我对 endpoints-proto-datastore 模块的高度理解来看,似乎当 json 被解码并保存到传入消息中时(utils.py 第 431 行),它没有检查结构化/本地结构化属性并将它们的键保存为这一切都很好,直到 FromValue(ndb/model.py 第 115 行)检查结构化属性的实例并尝试将结构化属性从 protorpc 消息递归转换为模型实体(需要 _Message__decoded_fields)。

Sasxa(请参阅上面的链接)通过使用转换为 ProtoRPC 消息类的 EndpointsAliasProperty 来绕过 endpoints-proto-datastore 将结构化属性自动转换为其关联的模型实体,找到了解决此问题的一个很好的解决方法,但是这种解决方法有一些方面使我想做的事情变得困难的效果。

问题:

有谁知道如何使用“POST”请求正确填充包含 StructuredProperty 的数据存储模型,并且有任何可用的工作示例吗?

4

0 回答 0