Skip to content

undefer_group() hasn't supported multiple since 0.9 #3623

Closed
@sqlalchemy-bot

Description

@sqlalchemy-bot
Collaborator

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
 

Activity

sqlalchemy-bot

sqlalchemy-bot commented on Jan 9, 2016

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

  • Fixed regression since 0.9 where the 0.9 style loader options
    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

sqlalchemy-bot commented on Jan 9, 2016

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

  • Fixed regression since 0.9 where the 0.9 style loader options
    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

sqlalchemy-bot commented on Jan 9, 2016

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
sqlalchemy-bot

sqlalchemy-bot commented on Jan 10, 2016

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

b301f00

added this to the 1.0.xx milestone on Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sqlalchemy-bot

        Issue actions

          undefer_group() hasn't supported multiple since 0.9 · Issue #3623 · sqlalchemy/sqlalchemy