Cannot define a method that returns a dict

Bug #481090 reported by Jonathan Lange
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lazr.restful
Triaged
Low
Unassigned

Bug Description

I'd like to define a method in Launchpad called BranchSet.getByUrls() that takes a list of URLs and returns some sort of collection of branches that map to those URLs. Ideally, I'd like to return a dict, mapping the URLs to branches. However, there's absolutely no mechanism for this in lazr.restful.

Further (and this might be a separate bug), if I simply return a list of branches (i.e. a collection of IBranch), then any None objects that I return from the server are excluded from the returned collection, preventing the client from matching URLs to branches via list index.

This means that there's no way to expose convenience methods that get multiple objects.

Revision history for this message
Jonathan Lange (jml) wrote :

https://code.edge.launchpad.net/~jml/launchpad/get-by-urls/+merge/14773 has a change that demonstrates the latter part of this bug.

Revision history for this message
Jonathan Lange (jml) wrote :

... and now demonstrates a work-around.

Revision history for this message
Gary Poster (gary) wrote :

Triaging this as low, with the understanding that improving the developer experience of launchpadlib is a high priority. If, after the focus on performance, we determine with Jonathan that addressing this is one of the big wins for launchpadlib usability, we will up the priority and schedule.

Changed in lazr.restful:
status: New → Triaged
importance: Undecided → Low
Revision history for this message
Robert Collins (lifeless) wrote :

I'd like to note that this has significant performance implications: looking up e.g. branches one at a time by getByUrl is very slow - seconds per, and I need to look up > 100 branches in a cron script.

getByUrls would be a lot faster, but hits this bug.

Revision history for this message
Robert Collins (lifeless) wrote :

21:28 < lifeless> leonardr: you were going to describe how to approach supporting a dict of objects as a return value
21:28 < leonardr> right
21:28 < leonardr> 1. create @returns_dict_of similar to @returns_collection_of
21:29 < leonardr> 2. come up with a wadl description of what @returns_dict_of means and put it in the wadl
21:29 < lifeless> whats the difference between a dict and a collection ?
21:29 < leonardr> a collection is a list
21:29 < lifeless> ok
21:29 < lifeless> if we're using non python names, should we say 'returns_map_of' ? :P
21:29 < leonardr> 3. have lazr.restful properly serialize a dict to json (this might work already)
21:30 < leonardr> 'collection' is a term from the atom publishing protocol. there's no corresponding term for 'map' so i don't think it matters much
21:31 < leonardr> 4. have lazr.restfulclient pick up on @returns_dict_of and handle it properly. old versions won't be able to handle the return value so we should probably do this in a new version of the web service

Revision history for this message
Gary Poster (gary) wrote :

After this is addressed, see bug 579516

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.