Edgewall Software

Ticket #191 (closed enhancement: fixed)

Opened 7 months ago

Last modified 6 months ago

Misleading error when an AttributeError exception is raised inside a property object

Reported by: michele Owned by: cmlenz
Priority: minor Milestone: 0.5
Component: Expression evaluation Version: 0.4.4
Keywords: Cc:

Description

When you try to access an attribute that uses a property object and an AttributeError? happens inside the getter method Genshi raises an UndefinedError? exception claiming that the object has not such attribute thus hiding the real exception.

This can be quite confusing (at first I thought Genshi didn't support python properties), it turns out this is not Genshi fault but a well know python issue/non-issue [1].

The patch I'm attaching uses a double check to prevent such an error, when accessing an attribute we don't let getattr manage the AttributeError? exception itself but we catch it and before trying to lookup the attribute using dictionary access we check if the object "really" has not such an attribute, note that I'm not using dir() but obj.class since properties/descriptors cannot be defined per instance but only at class level so this should be enough.

[1] http://mail.python.org/pipermail/python-dev/2005-December/058498.html

Attachments

property_attributeerror.patch (1.7 kB) - added by michele 7 months ago.
the patch

Change History

Changed 7 months ago by michele

the patch

Changed 6 months ago by cmlenz

  • status changed from new to closed
  • resolution set to fixed

Applied in [818]. Many thanks!

Add/Change #191 (Misleading error when an AttributeError exception is raised inside a property object)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.