On Dec 6, 2010, at 11:52 AM, Ian Thompson wrote: > On Dec 6, 4:49 pm, Ian Thompson <[email protected]> wrote: >> I've generated a test data set and then want to have all of the >> created objects and relationships available for reference easily. >> To avoid possible pollution of this fixture I want to detach the >> objects from the sessions to avoid them getting any updates applied. >> >> To do this I am attempting to load all data via joinedload and then >> calling session.expunge_all: >> >> print assets['test_asset_1'].attributes # OK >> >> session.query(Asset).options(joinedload(Asset.asset_attributes)).populate_e >> xisting().all() >> session.expunge_all() >> print assets['test_asset_1'].attributes # ERROR >> >> None of the relationships on the objects survive the expunge. >> >> sqlalchemy.orm.exc.DetachedInstanceError: >> Parent instance <Asset at ...> is not bound to a Session; >> lazy load operation of attribute 'asset_attributes' cannot proceed > (cont...) > Is there a correct way to detach all current data from the Session > fully loading any relationships? (Small data set so memory is not a > concern.)
This use case seems like it would be more easily solved using a new Session just for that load. To work with the objects detached, all "deferred" attributes and lazy-loading "relationship" attributes which you will need to access would need to either be eagerly loaded (there's now three ways to eagerly load relationship() attributes), or otherwise accessed via obj.attribute before the objects are expunged. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
