I am trying to code a Twitter-like microblogging application. In order to do that I'm using Google App Engine and the Datatstore.
I have two classes. The Tweet class which is the parent :
class Tweet(EndpointsModel):
_message_fields_schema = ('sender','body', 'name')
sender = ndb.StringProperty()
body = ndb.TextProperty()
created = ndb.DateTimeProperty(auto_now=True)
...
And the TweetIndex class, which is the child that contains all the receivers for a tweet.
class TweetIndex(EndpointsModel):
...
receivers = ndb.PickleProperty(indexed=True,repeated=True)
created = ndb.DateTimeProperty(auto_now=True)
...
@TweetIndex.method(request_fields=('receivers',),
path='mymodels', name='mymodel.list')
def MyModelList(self, query):
if not query.from_datastore:
raise endpoints.NotFoundException('MyModel not found.')
return query
I'm trying to query the TweetIndex entities with the API method MyModelList which purpose is to return the TweetIndex entity if a given id is included in the receivers array.
Example of a receivers array :
["13911772075915175317","1855429131779793831", ... ]
Which looks something like this in the datastore (stored as a blob):
["gAJYEwAAADY1NjU2NDM3MzA1NDI2NDU5ODlxAS4=","gAJYEwAAADU4MDM3MjE4OTEyNDgzNzgyNjNxAS4=",...]
However, when executing the following API request:
POST https://myapi/.../v1/mymodels
{
"receivers": [
"13911772075915175317"
]
}
The following is returned:
404
- Show headers -
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "MyModel not found."
}
],
"code": 404,
"message": "MyModel not found."
}
}
"13911772075915175317" does exist at least once in a receivers array. I also tried to input the blobs in the request (but with no surprise) did not work either.
How am I supposed to query this array correctly?
You'll need to query your receivers array with the pickled version. Given that a PickledProperty is binary data, it won't be easy to query. You are probably better off changing from PickledProperty to whatever type you actually want, in this case IntegerProperty.