[FIX] __getattr__ implementation on BaseModel
authorXavier Morel <xmo@openerp.com>
Fri, 15 Mar 2013 11:53:02 +0000 (12:53 +0100)
committerXavier Morel <xmo@openerp.com>
Fri, 15 Mar 2013 11:53:02 +0000 (12:53 +0100)
object has no __getattr__, in the usual case super(BaseModel,
self).__getattr__ will blow up with an AttributeError (but the wrong
one).

On the other hand, if a BaseModel descendant class is used in MI
alongside a non-BM descendant (e.g. res_partner inheriting from Model
and format_address) and the non-BM descendant also implements
__getattr__, we want to forward the failed attr search to the other
__getattr__ implementation.

So check if super() has a __getattr__, call it if it does otherwise
AttributeError right there.

bzr revid: xmo@openerp.com-20130315115302-z7jla334gb9a5e43

openerp/osv/orm.py

index 1efc9be..dd3a8ca 100644 (file)
@@ -5278,7 +5278,10 @@ class BaseModel(object):
             assert signal_name
             return (lambda *args, **kwargs:
                     self.signal_workflow(*args, signal=signal_name, **kwargs))
-        return super(BaseModel, self).__getattr__(name)
+        get = getattr(super(BaseModel, self), '__getattr__', None)
+        if get is not None: return get(name)
+        raise AttributeError(
+            "'%s' object has no attribute '%s'" % (type(self).__name__, name))
 
 # keep this import here, at top it will cause dependency cycle errors
 import expression