Closed
Description
Migrated issue, originally created by Michael Bayer (@zzzeek)
in 0.8, the undefer_group() option worked like this:
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:
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 --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
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
sqlalchemy-bot commentedon Jan 9, 2016
Michael Bayer (@zzzeek) wrote:
system failed to accommodate for multiple :func:
.undefer_group
loader options in a single query. Multiple :func:
.undefer_group
options will now be taken into account even against the same
entity. fixes undefer_group() hasn't supported multiple since 0.9 #3623
→ c7ae0da
sqlalchemy-bot commentedon Jan 9, 2016
Michael Bayer (@zzzeek) wrote:
system failed to accommodate for multiple :func:
.undefer_group
loader options in a single query. Multiple :func:
.undefer_group
options will now be taken into account even against the same
entity. fixes undefer_group() hasn't supported multiple since 0.9 #3623
(cherry picked from commit c7ae0da)
→ 61d2ceb
sqlalchemy-bot commentedon Jan 9, 2016
Changes by Michael Bayer (@zzzeek):
sqlalchemy-bot commentedon Jan 10, 2016
Michael Bayer (@zzzeek) wrote:
intelligible, given the fixes for ref undefer_group() hasn't supported multiple since 0.9 #3623. unfortunately the system
is still quite weird even though it was rewritten to be... less weird
→ b301f00