lazy はキャッシュしない方が

The issue I ran into with the above code dealt with related tables. The default behavior for SQLAlchemy is for related table attributes to be lazy-loaded. Once the orm object has been detached from session, the related attribute no longer has the ability to fetch the related data from the database. This can be fixed by disabling the lazy loading of relations in mappings that are going to be disconnected.

UserTable.mapper = mapper(User, UserTable, \
properties = { 'user_status': relation(UserStatus, lazy=False)})

lazy=(True|False|None|’dynamic’) –

specifies how the related items should be loaded. Values include:
True - items should be loaded lazily when the property is first
accessed.
False - items should be loaded “eagerly” in the same query as
that of the parent, using a JOIN or LEFT OUTER JOIN.
None - no loading should occur at any time. This is to support
“write-only” attributes, or attributes which are populated in some manner specific to the application.
‘dynamic’ - a DynaLoader will be attached, which returns a
Query object for all read operations. The dynamic- collection supports only append() and remove() for write operations; changes to the dynamic property will not be visible until the data is flushed to the database.

Page not found — SQLAlchemy 1.3 Documentation

lazy=’dynamic’ を使うと以下のような場合に
comments がロードされるのを回避できる。

comment1 = model.Comment()
comment1.name= u'James'
comment1.email = u'james@example.com'
comment1.content = u'This page needs a bit more detail ;-)'
comment2 = model.Comment()
comment2.name = u'Mike'
comment2.email = u'mike@example.com'
page.comments.append(comment1)
page.comments.append(comment2)
session.commit()

SQLAlchemy tutorial — MapFish