Post an ndb StructuredProperty _Message__decoded_fields

可紊 提交于 2019-12-20 04:23:29

问题


My Problem:

I am attempting to fill a datastore model in GAE that contains an ndb.Structured Property() using a 'POST' request.

This question has been asked recently but not answered (How to “POST” ndb.StructuredProperty?)

I have the following two models:

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

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

I'm trying to post this data:

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

with the following API request:

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

Upon posting from the client I receive the following error:

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

The Issue:

From my very high-level understanding of the endpoints-proto-datastore module it seems that when the json is being decoded and saved onto the incoming message (utils.py line 431) it's not checking for structured/localstructured properties and saving their keys as well which is all fine and dandy until FromValue (ndb/model.py line 115) checks for instances of structured properties and attempts to recursively convert the structured property from the protorpc message into a model entity (which needs the _Message__decoded_fields).

Sasxa (see the link above) had found a nifty little workaround to this issue by using an EndpointsAliasProperty converted to a ProtoRPC message class to bypass endpoints-proto-datastore's automatic conversion of the structuredproperty into its associated model entity, however this workaround had some side effects that made what I was trying to do difficult.

The Question:

Does anyone know how to correctly fill a datastore model containing a StructuredProperty using a 'POST' request, and are there any working examples of this available?

来源:https://stackoverflow.com/questions/36241087/post-an-ndb-structuredproperty-message-decoded-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!