diff options
Diffstat (limited to 'lib/sqlalchemy/orm/relationships.py')
| -rw-r--r-- | lib/sqlalchemy/orm/relationships.py | 22 |
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 |
