On Dec 6, 5:53 pm, Michael Bayer <mike...@zzzcomputing.com> wrote:
> On Dec 6, 2010, at 11:52 AM, Ian Thompson wrote:
>
>
>
>
>
> > On Dec 6, 4:49 pm, Ian Thompson <quorn...@gmail.com> 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.

Hi Michael, thanks for your reply.

I had thought by using joinedload (or eagerload) and populate_existing
I would be doing an eager load of the specified relation.

Also, in my example I do access the attributes relationship (with a
print), then after the expunge the same fails. Is there a way I can
ensure the data is preserved after expunging?

Thanks
Ian

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to