0

我正在尝试执行以下操作。基本上_message_fields_schema设置为不需要获取另一个 RPC 调用的有限属性(例如,引用其他对象的关键属性)。通过避免加载所有数据,这使我的查询更快。request_fields=MyModel.get_fields当我希望它们与 API 一起返回时,请允许我这样做。

但是,对于具有对 MyModel 的关键引用的对象,我认为应该执行以下操作,但我在代码后面看到了验证错误。知道这是一个错误还是我可能做错了什么?

class MyModel(EndpointsModel):

  # More expanded fields.
  get_fields = (...)
  # Default fields.
  _message_fields_schema = (...)


class MyOtherModel(EndpointsModel):

  my_obj_key = ndb.KeyProperty(MyModel)

  @EndpointsAliasProperty(
      property_type=MyModel.ProtoModel(fields=MyModel.get_fields),
      setter=MyObjSet)
  def my_obj(self):
    return self.my_obj_key.get()

错误堆栈跟踪。

Encountered unexpected error from ProtoRPC method implementation: ValidationError (Expected type <class '.MyModelProto_property1_property2_property3_property4'> for field myrecord, found <MyModel
 property1: 123
 property2: 'value2'
 property3: u'value3'
 property4: 'value4'> (type <class '.MyModel'>))
Traceback (most recent call last):
  File "google_appengine/lib/protorpc-1.0/protorpc/wsgi/service.py", line 181, in protorpc_service_app
    response = method(instance, request)
  File "google_appengine/lib/endpoints-1.0/endpoints/api_config.py", line 1332, in invoke_remote
    return remote_method(service_instance, request)
  File "google_appengine/lib/protorpc-1.0/protorpc/remote.py", line 412, in invoke_remote_method
    response = method(service_instance, request)
  File "third_party/py/endpoints_proto_datastore/ndb/model.py", line 1597, in QueryFromRequestMethod
    next_cursor=next_cursor)
  File "third_party/py/endpoints_proto_datastore/ndb/model.py", line 1275, in ToMessageCollection
    for item in items]
  File "third_party/py/endpoints_proto_datastore/ndb/model.py", line 1171, in ToMessage
    return proto_model(**proto_args)
  File "google_appengine/lib/protorpc-1.0/protorpc/messages.py", line 747, in __init__
    setattr(self, name, value)
  File "google_appengine/lib/protorpc-1.0/protorpc/messages.py", line 926, in __setattr__
    object.__setattr__(self, name, value)
  File "google_appengine/lib/protorpc-1.0/protorpc/messages.py", line 1559, in __set__
    super(MessageField, self).__set__(message_instance, value)
  File "google_appengine/lib/protorpc-1.0/protorpc/messages.py", line 1232, in __set__
    self.validate(value)
  File "google_appengine/lib/protorpc-1.0/protorpc/messages.py", line 1321, in validate
    self.__validate(value, self.validate_element)
  File "google_appengine/lib/protorpc-1.0/protorpc/messages.py", line 1287, in __validate
    validate_element(value)
  File "google_appengine/lib/protorpc-1.0/protorpc/messages.py", line 1272, in validate_element
    (self.type, name, value, type(value)))
4

0 回答 0