[New-bugs-announce] [issue27794] setattr a read-only property; the AttributeError should show the attribute that failed

Antti Haapala report at bugs.python.org
Thu Aug 18 09:57:19 EDT 2016


New submission from Antti Haapala:

Today we had an internal server error in production. I went to see the sentry logs for the error, and was dismayed: the error was `AttributeError: can't set attribute`, and the faulting line was `setattr(obj, attr, value)` that happens in a for-loop that uses computed properties coming from who knows.

Well, I quickly ruled out that it was because the code was trying to set a value to a read-only property descriptor, the only problem was to find out *which of all these read-only properties* was it trying to set:

Python 3.6.0a3+ (default, Aug 11 2016, 11:45:31) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class Foo:
...     @property
...     def bar(self): pass
... 
>>> setattr(Foo(), 'bar', 42)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: can't set attribute

Could we change this for Python 3.6 so that the message for this could include the name of the property just like `AttributeError: has no attribute 'baz'` does?

----------
messages: 273027
nosy: ztane
priority: normal
severity: normal
status: open
title: setattr a read-only property; the AttributeError should show the attribute that failed
type: enhancement

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27794>
_______________________________________


More information about the New-bugs-announce mailing list