Missing total_size on collections returned by named operations

Bug #274074 reported by Markus Korn
26
This bug affects 2 people
Affects Status Importance Assigned to Milestone
wadllib
Fix Released
Undecided
Leonard Richardson

Bug Description

As you can see in the attached example the result of the searchTasks method does not have attributes like total_size, so it does not behave like other collections:

In [30]: bughelper = launchpad.projects["bughelper"]

In [31]: bugs = bughelper.searchTasks()

In [32]: len(bugs)
---------------------------------------------------------------------------
<type 'exceptions.TypeError'> Traceback (most recent call last)

/media/disk-1/lp_api/launnchpadlib/trunk/<ipython console> in <module>()

/media/disk-1/lp_api/launnchpadlib/trunk/launchpadlib/resource.py in __len__(self)
    488 return int(self.total_size)
    489 except AttributeError:
--> 490 raise TypeError('collection size is not available')
    491
    492 def __iter__(self):

<type 'exceptions.TypeError'>: collection size is not available

Markus

Tags: api

Related branches

Revision history for this message
Leonard Richardson (leonardr) wrote :

This is a general problem with launchpadlib when dealing with collections that are the return values of named operations. Until this is fixed, use this workaround:

int(return_value._wadl_resource.representation['total_size'])

Changed in malone:
assignee: nobody → leonardr
summary: - result of searchTasks does not behave like other collections
+ Missing total_size on collections returned by named operations
Revision history for this message
Francis J. Lacoste (flacoste) wrote :

There is bug 303414 that is somewhat related.

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

Leonard, what's the "general problem" you refer to? Why not change the __len__ method of return_value to do what the work-around does?

Revision history for this message
James Westby (james-w) wrote :

See bug 529998 for a deeper dive in to this issue, though my knowledge wasn't
full enough to identify what should change to make this work. I'm keen to see a fix
for this, so with some help on that part I could work on it.

Thanks,

James

Revision history for this message
Leonard Richardson (leonardr) wrote :

I've verified that James' wadllib branch solves the launchpadlib problem. I've retargeted the bugtask.

affects: launchpadlib → wadllib
Revision history for this message
Leonard Richardson (leonardr) wrote :

The fix is available in wadllib 1.1.5.

Changed in wadllib:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

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