An @property replacement that reports AttributeErrors as PropertyFailedErrors
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Launchpad itself |
Triaged
|
Low
|
Unassigned |
Bug Description
Properties defined with "@property" that raise AttributeError can be confusing. For instance, if a view has an @property that has a bug and raises an AttributeError, then OOPS will give the impression that the attribute is missing entirely, leading the developer to look for typos in the template, or the wrong view being registered etc, rather than looking in the right place. And even when the developer does figure out to look in the right place, they won't know which part of the property function raised AttributeError.
We could write an alternative property decorator like this:
class errorhandlingpr
def __init__(self, fget):
self.fget = fget
def __get__(self, obj, objtype=None):
if obj is None:
return self
try:
return self.fget(obj)
except AttributeError, e:
raise PropertyFailedE
(Compare with the pure-python reference defintion of Property at http://
This would ensure that the different cases of "attribute does not exist" and "property failed to work" are reported differently.
Changed in launchpad-foundations: | |
status: | New → Triaged |
importance: | Undecided → Low |
From the point of view of "finding where the error occurred, won't this place the end of the traceback at the "raise PropertyFailedE rror" bit, obscuring the real location of the exception?