Commits

Mike Bayer committed d914493

- add some tests for propagate of wildcard lazyload

  • Participants
  • Parent commits 22d5a1e

Comments (0)

Files changed (3)

lib/sqlalchemy/orm/interfaces.py

         # that the path is stated in terms of our base
         search_path = dict.__getitem__(path, self)
 
-        #if self.key == "email_address":
-        #    import pdb
-        #    pdb.set_trace()
         # search among: exact match, "attr.*", "default" strategy
         # if any.
         for path_key in (

lib/sqlalchemy/orm/strategy_options.py

             if attr.endswith(_WILDCARD_TOKEN) or attr.endswith(_DEFAULT_TOKEN):
                 if wildcard_key:
                     attr = "%s:%s" % (wildcard_key, attr)
-                self.propagate_to_loaders = False
+                if attr.endswith(_DEFAULT_TOKEN):
+                    self.propagate_to_loaders = False
                 return path.token(attr)
 
             try:
         if wildcard_key and isinstance(attr, util.string_types) and \
                 attr in (_WILDCARD_TOKEN, _DEFAULT_TOKEN):
             attr = "%s:%s" % (wildcard_key, attr)
-            self.propagate_to_loaders = False
+            if attr == _DEFAULT_TOKEN:
+                self.propagate_to_loaders = False
 
         return path + (attr, )
 
         current_path = query._current_path
         if current_path:
             start_path = self._chop_path(start_path, current_path)
+
         if not start_path:
             return None
 

test/orm/test_eager_relations.py

 import sqlalchemy as sa
 from sqlalchemy import testing
 from sqlalchemy.orm import joinedload, deferred, undefer, \
-    joinedload_all, backref, eagerload, Session, immediateload
+    joinedload_all, backref, eagerload, Session, immediateload,\
+    defaultload, Load
 from sqlalchemy import Integer, String, Date, ForeignKey, and_, select, \
     func
 from sqlalchemy.testing.schema import Table, Column
             "WHERE orders.description = :description_1"
         )
 
+    def test_propagated_lazyload_wildcard_unbound(self):
+        self._test_propagated_lazyload_wildcard(False)
+
+    def test_propagated_lazyload_wildcard_bound(self):
+        self._test_propagated_lazyload_wildcard(True)
+
+    def _test_propagated_lazyload_wildcard(self, use_load):
+        users, items, order_items, Order, Item, User, orders = (self.tables.users,
+                                self.tables.items,
+                                self.tables.order_items,
+                                self.classes.Order,
+                                self.classes.Item,
+                                self.classes.User,
+                                self.tables.orders)
+
+        mapper(User, users, properties=dict(
+            orders=relationship(Order, lazy="select")
+        ))
+        mapper(Order, orders, properties=dict(
+            items=relationship(Item, secondary=order_items, lazy="joined")
+        ))
+        mapper(Item, items)
+
+        sess = create_session()
+
+        if use_load:
+            opt = Load(User).defaultload("orders").lazyload("*")
+        else:
+            opt = defaultload("orders").lazyload("*")
+
+        q = sess.query(User).filter(User.id == 7).options(opt)
+
+        def go():
+            for u in q:
+                u.orders
+
+        self.sql_eq_(go, [
+            ("SELECT users.id AS users_id, users.name AS users_name "
+                "FROM users WHERE users.id = :id_1", {"id_1": 7}),
+            ("SELECT orders.id AS orders_id, orders.user_id AS orders_user_id, "
+            "orders.address_id AS orders_address_id, "
+            "orders.description AS orders_description, "
+            "orders.isopen AS orders_isopen FROM orders "
+            "WHERE :param_1 = orders.user_id", {"param_1": 7}),
+        ])
+
 
 
 class SubqueryAliasingTest(fixtures.MappedTest, testing.AssertsCompiledSQL):