asolfre / appengine-rest-server

Automatically exported from code.google.com/p/appengine-rest-server
Other
0 stars 0 forks source link

List properties of db.Key values don't appear properly #29

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When accessing a list property, one only gets the keys of the child elements 
instead of a list of the child elements:

e.g.
http:{service}//rest/ParentModel/{Parent_Key}/Property
should return a list of Property instances instead of a list of db.key that 
have to be fetched one-by-one from the database.

Original issue reported on code.google.com by michael....@gmail.com on 10 Apr 2011 at 12:04

GoogleCodeExporter commented 9 years ago
A little more details: 
Consider something like a bookmarking service that has urls and a list of tags 
(of type Tag). 

The Model:

def Bookmark(db.Model):
    url = db.StringProperty()
    tags = db.ListProperty(db.Key)

The RESTful call:
http://localhost:8080/rest/Bookmark/abcdefgh012345/tags/

returns 

[datastore_types.Key.from_path(u'Tag', 2, _app=u'my-project'), 
datastore_types.Key.from_path(u'Tag', 6, _app=u'my-project')]

instead of a list of two Tag objects

Original comment by michael....@gmail.com on 10 Apr 2011 at 12:38

GoogleCodeExporter commented 9 years ago
i'm not sure i understand the issue.  are you saying that the keys are not 
appearing correctly, or that you want the actual Model objects instead of the 
keys?  if the former, that's a bug.  if the latter, that is by design.

Original comment by jahlborn@gmail.com on 10 Apr 2011 at 1:23

GoogleCodeExporter commented 9 years ago
It's both, I guess.
The keys are not appearing correctly, as you can see above.
The REST service should not return 
[datastore_types.Key.from_path(u'Tag', 2, _app=u'my-project'), 
datastore_types.Key.from_path(u'Tag', 6, _app=u'my-project')]

But also, I would like to get the actual Model objects if I query for list 
parameters. As far as I understand, it's standard behavior for a RESTful 
service that nested models can be retrieved like that. 
Or is there another way to get to those nested objects apart from sending a 
request to the server querying for the object by key one-by-one?

Original comment by michael....@gmail.com on 10 Apr 2011 at 1:28

GoogleCodeExporter commented 9 years ago
well, i don't claim that this service is 100% RESTful, as that's a difficult 
target.  the truly RESTful way is that every object includes complete urls to 
reference other objects.  instead, this service returns keys (which can be 
trivially converted to urls) which can be used to retrieve referenced objects.  
so, there does seem to be a bug in that the keys are returned incorrectly.  but 
otherwise, i think that returning the keys is correct RESTful behavior.

Original comment by jahlborn@gmail.com on 10 Apr 2011 at 2:47

GoogleCodeExporter commented 9 years ago
I see. Thanks for the reply. Would you consider that an extension anytime in 
the future? You seem to have everything in place already (the handlers etc.), 
so the missing piece would be adding that one level of recursion.

In any case, thanks for taking care of that bug.

Original comment by michael....@gmail.com on 10 Apr 2011 at 3:29

GoogleCodeExporter commented 9 years ago
yeah, i was thinking maybe you could include something in the url which 
indicates that you want to "dereference" the keys instead of just returning 
them.  interesting idea.

Original comment by jahlborn@gmail.com on 10 Apr 2011 at 6:30

GoogleCodeExporter commented 9 years ago
That sounds like a great suggestion! Looking forward to something like that.

Original comment by michael....@gmail.com on 10 Apr 2011 at 6:38

GoogleCodeExporter commented 9 years ago
split the enhancement request out into a separate issue, issue 30.

Original comment by jahlborn@gmail.com on 10 Apr 2011 at 11:56

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r58.

Original comment by jahlborn@gmail.com on 10 May 2011 at 1:00

GoogleCodeExporter commented 9 years ago
This will now return an xml/json list as appropriate to the accept header.  
additionally, i added support for retrieving an individual element of the list 
using the syntax "<model>/<key>/<property>/<index>" (note, this will still 
return the key _value_, haven't figured out the best way to add support for 
dereferencing the keys yet).

Original comment by jahlborn@gmail.com on 10 May 2011 at 2:28

GoogleCodeExporter commented 9 years ago

Original comment by jahlborn@gmail.com on 6 Jun 2012 at 1:10