Edgewall Software

Ticket #191 (closed enhancement: fixed)

Opened 4 years ago

Last modified 4 years 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 Download (1.7 KB) - added by michele 4 years ago.
the patch

Change History

Changed 4 years ago by michele

the patch

Changed 4 years 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


E-mail address and user name can be saved in the Preferences.


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