launchpad-dev team mailing list archive
-
launchpad-dev team
-
Mailing list archive
-
Message #02874
odd test failure for an IHasBugs attribute of an IPerson object
Hi all,
I get a test failure for the branch
lp:~adeuring/launchpad/bug-528788-no-searchbox-without-hot-bugs in
lib/lp/registry/tests/../doc/person.txt that I do not understand:
File "lib/lp/registry/tests/../doc/person.txt", line 23, in person.txt
Failed example:
verifyObject(IPerson, foobar)
Exception raised:
Traceback (most recent call last):
File
"/home/abel/canonical/lp-branches/trunk/eggs/zope.testing-3.8.1-py2.5.egg/zope/testing/doctest.py",
line 1361, in __run
compileflags, 1) in test.globs
File "<doctest person.txt[line 23, example 7]>", line 1, in <module>
verifyObject(IPerson, foobar)
File
"/home/abel/canonical/lp-branches/bug-528788-no-searchbox-without-hot-bugs/lib/canonical/launchpad/webapp/testing.py",
line 18, in verifyObject
return zope_verifyObject(iface, naked_candidate, tentative=0)
File
"/home/abel/canonical/lp-branches/trunk/eggs/zope.interface-3.5.2-py2.5-linux-x86_64.egg/zope/interface/verify.py",
line 97, in verifyObject
return _verify(iface, candidate, tentative, vtype='o')
File
"/home/abel/canonical/lp-branches/trunk/eggs/zope.interface-3.5.2-py2.5-linux-x86_64.egg/zope/interface/verify.py",
line 63, in _verify
raise BrokenImplementation(iface, name)
BrokenImplementation: An object has failed to implement interface
<InterfaceClass lp.registry.interfaces.person.IPerson>
The has_bugtasks attribute was not provided.
The attribute has_bugtasks is implemented in
lp.bugs.model.bugtarget.HasBugsBase , and class Person inherits this class.
If I add the line
>>> foobar.has_bugtasks
to the doc test, I get a slightly more specific error:
File "lib/lp/registry/tests/../doc/person.txt", line 25, in person.txt
Failed example:
foobar.has_bugtasks
Exception raised:
Traceback (most recent call last):
File
"/home/abel/canonical/lp-branches/trunk/eggs/zope.testing-3.8.1-py2.5.egg/zope/testing/doctest.py",
line 1361, in __run
compileflags, 1) in test.globs
File "<doctest person.txt[line 25, example 8]>", line 1, in <module>
foobar.has_bugtasks
File
"/home/abel/canonical/lp-branches/bug-528788-no-searchbox-without-hot-bugs/lib/lp/bugs/model/bugtarget.py",
line 254, in has_bugtasks
all_tasks = all_tasks.limit(1)
ForbiddenAttribute: ('limit', <storm.sqlobject.SQLObjectResultSet
object at 0xef90690>)
HasBugsBase.has_bugtasks is quite simple:
def has_bugtasks(self):
"""See `IHasBugs`."""
# Basically, the return value is self.all_bugtasks.count() > 0.
# But finding, sorting and counting all bug tasks can take
# a longer time (long enough that the HTML data for "number of
# open, critical etc bugs" on a bug page is retrieved in a
# separate request). all_bugtasks returns a
# storm.SQLObjectResultSet instance, and this class does not
# provide methods like is_empty(), so limit the query
# manually and simply check if at least one bug task exists.
all_tasks = self.all_bugtasks
all_tasks = all_tasks.limit(1)
return all_tasks.count() > 0
So, we can't call foobar.all_bugtasks.limit(1) -- while calls like
product.all_bugtasks.limit(1) do not cause any problem.
Can somebody enlighten me how to fix this properly? An obvious
workaround would be to use removeSecurityProxy(self.all_bugtasks) -- but
I'd like to understand what is so special about class Person that things
like
>>> for task on foobar.all_bugtasks:
... print task
work, while foobar.all_bugtasks.limit(1) fails...
Abel
Follow ups