Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Endpoints API - protorpc validation error

I'm getting some weird errors from protorpc when I use endpoints. In this code:

class Application(EndpointsModel):      _message_fields_schema = ('id', 'name')      created = ndb.DateTimeProperty(auto_now_add=True)     name = ndb.StringProperty()     roles = ndb.IntegerProperty(repeated=True)     updated = ndb.DateTimeProperty(auto_now=True)     owner = ndb.KeyProperty(kind='User')  @API.api_class(resource_name="application") class ApplicationApi(protorpc.remote.Service):      @Application.method(http_method="GET",                         request_fields=('id',),                         name="get",                         path="applications/{id}")     def ApplicationGet(self, instance):         if not instance.from_datastore:             raise endpoints.NotFoundException("Application not found.")         return instance      @Application.query_method(http_method="GET",                               query_fields=('limit', 'order', 'pageToken'),                               name="list",                               path="applications")     def ApplicationList(self, query):         return query 

when I call application.get() error is as follows: (full trace here):

TypeError: Can only copy from entities of the exact type Application. Received an instance of Application.

and for calling application.list() error is as follows: (full trace here):

ValidationError: Expected type <class '.Application'> for field items, found <Application name: u'test'> (type <class '.Application'>)

What could be causing this? My other models with pretty much the same code (just different properties) work fine.

like image 599
Sasxa Avatar asked Feb 21 '16 18:02

Sasxa


1 Answers

Subclass class JsonModel(EndpointsModel) to make it start working again.

like image 176
J_H Avatar answered Sep 19 '22 17:09

J_H