summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/relationships.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-12-12 12:49:57 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2013-12-12 12:49:57 -0500
commitace7bdbc78571619cb103d57a188fbe6aa92b627 (patch)
treedaa52736c7bcd396894d405d05374550d0693783 /lib/sqlalchemy/orm/relationships.py
parent9bef2001a604b520a82abc65cf95790211d36106 (diff)
downloadsqlalchemy-ace7bdbc78571619cb103d57a188fbe6aa92b627.tar.gz
- Error message when a string arg sent to :func:`.relationship` which
doesn't resolve to a class or mapper has been corrected to work the same way as when a non-string arg is received, which indicates the name of the relationship which had the configurational error. [ticket:2888]
Diffstat (limited to 'lib/sqlalchemy/orm/relationships.py')
-rw-r--r--lib/sqlalchemy/orm/relationships.py22
1 files changed, 10 insertions, 12 deletions
diff --git a/lib/sqlalchemy/orm/relationships.py b/lib/sqlalchemy/orm/relationships.py
index 8296be60a..c1cf07fbe 100644
--- a/lib/sqlalchemy/orm/relationships.py
+++ b/lib/sqlalchemy/orm/relationships.py
@@ -1348,23 +1348,21 @@ class RelationshipProperty(StrategizedProperty):
This is a lazy-initializing static attribute.
"""
- if isinstance(self.argument, type):
- mapper_ = mapperlib.class_mapper(self.argument,
- configure=False)
- elif isinstance(self.argument, mapperlib.Mapper):
- mapper_ = self.argument
- elif util.callable(self.argument):
-
- # accept a callable to suit various deferred-
- # configurational schemes
+ if util.callable(self.argument) and \
+ not isinstance(self.argument, (type, mapperlib.Mapper)):
+ argument = self.argument()
+ else:
+ argument = self.argument
- mapper_ = mapperlib.class_mapper(self.argument(),
+ if isinstance(argument, type):
+ mapper_ = mapperlib.class_mapper(argument,
configure=False)
+ elif isinstance(self.argument, mapperlib.Mapper):
+ mapper_ = argument
else:
raise sa_exc.ArgumentError("relationship '%s' expects "
"a class or a mapper argument (received: %s)"
- % (self.key, type(self.argument)))
- assert isinstance(mapper_, mapperlib.Mapper), mapper_
+ % (self.key, type(argument)))
return mapper_
@util.memoized_property