cache key error w/ undefer group on top of defaultload, 1.2 regression w/ lazyload caching

Issue #4049 resolved
Michael Bayer
repo owner created an issue

related to #4048, we can't even get to the lazyload for this one

    def test_undefer_group_from_relationship_lazyload(self):
        users, Order, User, orders = \

        mapper(User, users, properties=dict(
            Order, orders, properties=util.OrderedDict([
                ('userident', deferred(orders.c.user_id, group='primary')),
                ('description', deferred(orders.c.description,
                ('opened', deferred(orders.c.isopen, group='primary'))

        sess = create_session()
        q = sess.query(User).filter( == 7).options(

        def go():
            result = q.all()
            o2 = result[0].orders[1]
            eq_(o2.opened, 1)
            eq_(o2.userident, 7)
            eq_(o2.description, 'order 3')
        self.assert_sql_count(testing.db, go, 1)


Traceback (most recent call last):
  File "/home/classic/dev/sqlalchemy/test/orm/", line 419, in test_undefer_group_from_relationship_lazyload
    self.assert_sql_count(testing.db, go, 1)
  File "/home/classic/dev/sqlalchemy/test/../lib/sqlalchemy/testing/", line 520, in assert_sql_count
    db, callable_, assertsql.CountStatements(count))
  File "/home/classic/dev/sqlalchemy/test/../lib/sqlalchemy/testing/", line 500, in assert_sql_execution
    result = callable_()
  File "/home/classic/dev/sqlalchemy/test/orm/", line 415, in go
    o2 = result[0].orders[1]
  File "/home/classic/dev/sqlalchemy/test/../lib/sqlalchemy/orm/", line 242, in __get__
    return self.impl.get(instance_state(instance), dict_)
  File "/home/classic/dev/sqlalchemy/test/../lib/sqlalchemy/orm/", line 603, in get
    value = self.callable_(state, passive)
  File "/home/classic/dev/sqlalchemy/test/../lib/sqlalchemy/orm/", line 623, in _load_for_state
    return self._emit_lazyload(session, state, ident_key, passive)
  File "<string>", line 1, in <lambda>
  File "/home/classic/dev/sqlalchemy/test/../lib/sqlalchemy/orm/", line 714, in _emit_lazyload
    state.load_options, effective_path
  File "/home/classic/dev/sqlalchemy/test/../lib/sqlalchemy/ext/", line 178, in _add_lazyload_options
    cache_key = opt._generate_cache_key(cache_path)
  File "/home/classic/dev/sqlalchemy/test/../lib/sqlalchemy/orm/", line 389, in _generate_cache_key
    c_key = opt._generate_cache_key(path)
  File "/home/classic/dev/sqlalchemy/test/../lib/sqlalchemy/orm/", line 113, in _generate_cache_key
    obj.strategy +
TypeError: can only concatenate tuple (not "NoneType") to tuple

Comments (1)

  1. Michael Bayer reporter

    Handle cache key for option that has no strategy

    Fixed regression where the use of a :func:.undefer_group option in conjunction with a lazy loaded relationship option would cause an attribute error, due to a bug in the SQL cache key generation added in 1.2 as part of 🎫3954.

    Change-Id: Icd9a34f0b5aa96d6433a2ab9c8d3eaee0006f609 Fixes: #4049

    → <<cset 3f9df2b86b4a>>

  2. Log in to comment