[Sqlalchemy-tickets] Issue #3623: undefer_group() hasn't supported multiple since 0.9 (zzzeek/sqlal
Brought to you by:
zzzeek
From: Mike B. <iss...@bi...> - 2016-01-09 14:29:23
|
New issue 3623: undefer_group() hasn't supported multiple since 0.9 https://bitbucket.org/zzzeek/sqlalchemy/issues/3623/undefer_group-hasnt-supported-multiple Mike Bayer: in 0.8, the undefer_group() option worked like this: ``` #!python class UndeferGroupOption(MapperOption): propagate_to_loaders = True def __init__(self, group): self.group = group def process_query(self, query): query._attributes[("undefer", self.group)] = True ``` in 0.9 and above, like this: ``` #!python return loadopt.set_column_strategy( "*", None, {"undefer_group": name} ) ``` the difference is obvious in that the latter is setting the name as a unique dictionary value! new test: ``` #!diff diff --git a/test/orm/test_deferred.py b/test/orm/test_deferred.py index 29087fd..96dce7f 100644 --- a/test/orm/test_deferred.py +++ b/test/orm/test_deferred.py @@ -320,6 +320,35 @@ class DeferredOptionsTest(AssertsCompiledSQL, _fixtures.FixtureTest): "FROM orders ORDER BY orders.id", {})]) + def test_undefer_group_multi(self): + orders, Order = self.tables.orders, self.classes.Order + + mapper(Order, orders, properties=util.OrderedDict([ + ('userident', deferred(orders.c.user_id, group='primary')), + ('description', deferred(orders.c.description, group='primary')), + ('opened', deferred(orders.c.isopen, group='secondary')) + ] + )) + + sess = create_session() + q = sess.query(Order).order_by(Order.id) + def go(): + l = q.options( + undefer_group('primary'), undefer_group('secondary')).all() + o2 = l[2] + eq_(o2.opened, 1) + eq_(o2.userident, 7) + eq_(o2.description, 'order 3') + + self.sql_eq_(go, [ + ("SELECT orders.user_id AS orders_user_id, " + "orders.description AS orders_description, " + "orders.isopen AS orders_isopen, " + "orders.id AS orders_id, " + "orders.address_id AS orders_address_id " + "FROM orders ORDER BY orders.id", + {})]) + def test_undefer_star(self): orders, Order = self.tables.orders, self.classes.Order ``` |