对象没有_Message__decoded_fields属性

时间:2023-01-06 23:10:05

I have two models:

我有两个型号:

class Location(EndpointsModel):
    geoLocation = ndb.GeoPtProperty()
    street = ndb.StringProperty()
    city = ndb.StringProperty()
    state = ndb.StringProperty()

class UserPost(EndpointsModel):
    _message_fields_schema = ("entityKey", "title", "description", "category", "date", "time", "status", "locationOne")
    category = ndb.IntegerProperty(indexed=True,validator=checkIfValidCategory)
    title = ndb.StringProperty()
    description = ndb.TextProperty()
    date = ndb.DateProperty(indexed=True,auto_now_add=True)
    time = ndb.IntegerProperty(indexed=True)
    status = ndb.IntegerProperty(indexed=True,validator=checkIfValidStatusType) 
    locationOne = ndb.StructuredProperty(Location,indexed=False)

I am attempting an insert on UserPost via the following method:

我正在尝试通过以下方法在UserPost上插入:

@UserPost.method(name='userPost.insert', path='userPost/insert', http_method='POST')
def userPost_insert(self,r):
    """ insert userPost """
    user = Auth.get_current_user(verified_email_required=True)
    if user is None:
        raise endpoints.UnauthorizedException('You must have a verified account before you can post')
    if r.title is None:
        raise endpoints.BadRequestException('Missing title')
    i_post = r
    i_post.put()
    return i_post

This is the JSON coming from the client:

这是来自客户端的JSON:

{
    "title":"asdf",
    "details":"asdf",
    "locationOne":{
        "state":"test",
        "geoLocation":{
            "lon":0.127592,
            "lat":51.503407051
        },
        "city":"test",
        "street":"test"
    }
}

It works if I take out locationOne however when I attempt an insert with the location I get an error. Here is my stack trace:

它可以工作,如果我拿出locationOne然而当我尝试插入位置我得到一个错误。这是我的堆栈跟踪:

INFO     2016-03-25 17:08:52,389 module.py:787] default: "POST /_ah/spi/Auth.CurrentUser HTTP/1.1" 200 207
INFO     2016-03-25 17:08:52,389 module.py:787] default: "GET /_ah/api/auth/v1.0/current_user HTTP/1.1" 200 224
INFO     2016-03-25 17:09:01,631 module.py:787] default: "POST /_ah/spi/BackendService.getApiConfigs HTTP/1.1" 200 95185
ERROR    2016-03-25 17:09:01,644 service.py:191] Encountered unexpected error from ProtoRPC method implementation: AttributeError ('Location' object has no attribute '_Message__decoded_fields')
Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/protorpc-1.0/protorpc/wsgi/service.py", line 181, in protorpc_service_app
    response = method(instance, request)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/endpoints-1.0/endpoints/api_config.py", line 1331, in invoke_remote
    return remote_method(service_instance, request)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/protorpc-1.0/protorpc/remote.py", line 414, in invoke_remote_method
    response = method(service_instance, request)
  File "/Users/buddydelaune/Dev/Apps/noble-py-proto/endpoints_proto_datastore/ndb/model.py", line 1408, in EntityToRequestMethod
    request = cls.FromMessage(request)
  File "/Users/buddydelaune/Dev/Apps/noble-py-proto/endpoints_proto_datastore/ndb/model.py", line 1232, in FromMessage
    to_add = FromValue(value_property, value)
  File "/Users/buddydelaune/Dev/Apps/noble-py-proto/endpoints_proto_datastore/ndb/model.py", line 139, in FromValue
    return modelclass.FromMessage(value)
  File "/Users/buddydelaune/Dev/Apps/noble-py-proto/endpoints_proto_datastore/ndb/model.py", line 1216, in FromMessage
    if not field.name in message._Message__decoded_fields:
AttributeError: 'Location' object has no attribute '_Message__decoded_fields'

Any insight into this would be greatly appreciated. Thanks ahead of time.

任何有关这方面的见解将不胜感激。提前谢谢。

2 个解决方案

#1


0  

I'm not familiar with the EndpointsModel but looking at your code, I can see that the Location model doesn't have an entry for

我不熟悉EndpointsModel但是查看你的代码,我可以看到Location模型没有条目

_message_fields_schema

like you have for the UserPost model. Why don't you try putting that and see if it solves the problem?

就像你有UserPost模型一样。你为什么不尝试这样做,看看它是否解决了这个问题?

#2


0  

Sorry I should've answered this question earlier, but this issue has been fixed. It was actually a bug with the endpoints-proto-datastore model in which the incoming json was not being correctly parsed and converted into their respective datastore entities. I posted a better description of this problem here and you can see the fix implemented here.

对不起,我应该早点回答这个问题,但这个问题已得到解决。这实际上是端点 - 原型数据存储模型的一个错误,其中传入的json未被正确解析并转换为它们各自的数据存储实体。我在这里发布了对这个问题的更好的描述,你可以看到这里实现的修复。

#1


0  

I'm not familiar with the EndpointsModel but looking at your code, I can see that the Location model doesn't have an entry for

我不熟悉EndpointsModel但是查看你的代码,我可以看到Location模型没有条目

_message_fields_schema

like you have for the UserPost model. Why don't you try putting that and see if it solves the problem?

就像你有UserPost模型一样。你为什么不尝试这样做,看看它是否解决了这个问题?

#2


0  

Sorry I should've answered this question earlier, but this issue has been fixed. It was actually a bug with the endpoints-proto-datastore model in which the incoming json was not being correctly parsed and converted into their respective datastore entities. I posted a better description of this problem here and you can see the fix implemented here.

对不起,我应该早点回答这个问题,但这个问题已得到解决。这实际上是端点 - 原型数据存储模型的一个错误,其中传入的json未被正确解析并转换为它们各自的数据存储实体。我在这里发布了对这个问题的更好的描述,你可以看到这里实现的修复。