diff options
author | Dmytro Starosud <d.starosud@gmail.com> | 2019-05-29 16:47:13 +0300 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-05-29 17:07:35 -0400 |
commit | 5ac10699e1111283ae848f9d3a6dcc4e09d8c1ef (patch) | |
tree | 2cee514317fc01465e4a61ff5ea51392a2727197 /lib/sqlalchemy/orm/attributes.py | |
parent | 142c94348ad4a341f7cbff3d76bf0df397fa782f (diff) | |
download | sqlalchemy-5ac10699e1111283ae848f9d3a6dcc4e09d8c1ef.tar.gz |
Rework AliasedClass __getattr__ to use top-level getattr()
Reworked the attribute mechanics used by :class:`.AliasedClass` to no
longer rely upon calling ``__getattribute__`` on the MRO of the wrapped
class, and to instead resolve the attribute normally on the wrapped class
using getattr(), and then unwrap/adapt that. This allows a greater range
of attribute styles on the mapped class including special ``__getattr__()``
schemes; but it also makes the code simpler and more resilient in general.
Fixes: #4694
Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com>
Change-Id: I28901e2472d3c21e881fe5cafa3b1d3af704fad8
Diffstat (limited to 'lib/sqlalchemy/orm/attributes.py')
-rw-r--r-- | lib/sqlalchemy/orm/attributes.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 321ab7d6f..74ebe40f6 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -346,10 +346,14 @@ def create_proxied_attribute(descriptor): ) def __get__(self, instance, owner): - if instance is None: + retval = self.descriptor.__get__(instance, owner) + # detect if this is a plain Python @property, which just returns + # itself for class level access. If so, then return us. + # Otherwise, return the object returned by the descriptor. + if retval is self.descriptor and instance is None: return self else: - return self.descriptor.__get__(instance, owner) + return retval def __str__(self): return "%s.%s" % (self.class_.__name__, self.key) |