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.
Application
instead of the class(type) objectApplication
. Are you sure you aren't usingApplication()
somewhere in your code? – InfeldApplicationApi(BaseRemoteService)
, but no mention of Application there, and there's a POST api method (which works...), but even if I remove all that I'm still getting the same errors with just the code from OP. – AyahEndpointsModel
, didApplication
subclassndb.Model
? Try looping through allApplication
entities and doing aput
again on them. I'm thinking that the key you pass in fetches the entity but something about the inheritance chain is making the__class__
fields not match. – InfeldApplication
class didn't subclass anything other thenEndpointsModel
, but when I subclassedclass JsonModel(EndpointsModel)
(also did some other things in code, so can't be sure what exactly is happening) it started working. I reverted back toEndpointsModel
and it's still workig (; Guess the only way to deal with thiss kind of issues is to turn everything else off and isolate modules with problems... – Ayah