I am trying to do something like the following. Basically _message_fields_schema
is set to limited properties that doesn't require another RPC calls to be fetched (e.g. key properties referencing other objects). This allow my queries to be faster by avoiding loading all that data. And allow me to do request_fields=MyModel.get_fields
to get these when I want them returned with the APIs.
However, for an object that has a key reference to MyModel, I thought something like the following should do it but I am seeing a validation error at as see following the code. Any idea if this is a bug or if I might be doing something wrong?
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()
Error stack trace.
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)))