loader options from non_primary mappers
Issue #3348
new
e.g. query.options(joinedload_all("a.bs_np.c")), where "bs_np" refers to a non primary mapper. can't use getattr() here:
diff --git a/lib/sqlalchemy/orm/strategy_options.py b/lib/sqlalchemy/orm/strategy_options.py
index cb7a5fe..70f4caa 100644
--- a/lib/sqlalchemy/orm/strategy_options.py
+++ b/lib/sqlalchemy/orm/strategy_options.py
@@ -128,21 +128,24 @@ class Load(Generative, MapperOption):
attr = "%s:%s" % (wildcard_key, attr)
return path.token(attr)
- try:
- # use getattr on the class to work around
- # synonyms, hybrids, etc.
- attr = getattr(path.entity.class_, attr)
- except AttributeError:
- if raiseerr:
- raise sa_exc.ArgumentError(
- "Can't find property named '%s' on the "
- "mapped entity %s in this Query. " % (
- attr, path.entity)
- )
- else:
- return None
+ if path.entity.non_primary:
+ attr = path.entity._props[attr]
else:
- attr = attr.property
+ try:
+ # use getattr on the class to work around
+ # synonyms, hybrids, etc.
+ attr = getattr(path.entity.class_, attr)
+ except AttributeError:
+ if raiseerr:
+ raise sa_exc.ArgumentError(
+ "Can't find property named '%s' on the "
+ "mapped entity %s in this Query. " % (
+ attr, path.entity)
+ )
+ else:
+ return None
+ else:
+ attr = attr.property
path = path[attr]
else:
this might apply to 0.9 as well.
Comments (5)
-
reporter -
reporter - changed milestone to 1.1
this is probably something that's never worked so lets make sure we get to it...
-
reporter - changed milestone to 1.2
-
reporter - changed milestone to 1.x.xx
-
reporter - marked as enhancement
- Log in to comment
plus there's not even a way to use real attributes: "ArgumentError: Attribute 'B.c1s' does not link from element 'Mapper|B|Join object on b(4360539024) and c1(4360529104)|non-primary'"