summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/attributes.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/orm/attributes.py')
-rw-r--r--lib/sqlalchemy/orm/attributes.py31
1 files changed, 21 insertions, 10 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py
index e277f6f5b..d47740e3d 100644
--- a/lib/sqlalchemy/orm/attributes.py
+++ b/lib/sqlalchemy/orm/attributes.py
@@ -361,23 +361,34 @@ def create_proxied_attribute(descriptor):
def __getattr__(self, attribute):
"""Delegate __getattr__ to the original descriptor and/or
comparator."""
-
try:
return getattr(descriptor, attribute)
except AttributeError:
+ if attribute == "comparator":
+ raise AttributeError("comparator")
try:
- return getattr(self.comparator, attribute)
+ # comparator itself might be unreachable
+ comparator = self.comparator
except AttributeError:
raise AttributeError(
- "Neither %r object nor %r object associated with %s "
- "has an attribute %r"
- % (
- type(descriptor).__name__,
- type(self.comparator).__name__,
- self,
- attribute,
- )
+ "Neither %r object nor unconfigured comparator "
+ "object associated with %s has an attribute %r"
+ % (type(descriptor).__name__, self, attribute)
)
+ else:
+ try:
+ return getattr(comparator, attribute)
+ except AttributeError:
+ raise AttributeError(
+ "Neither %r object nor %r object "
+ "associated with %s has an attribute %r"
+ % (
+ type(descriptor).__name__,
+ type(comparator).__name__,
+ self,
+ attribute,
+ )
+ )
Proxy.__name__ = type(descriptor).__name__ + "Proxy"