On Apr 7, 2011, at 9:54 PM, BenH wrote:

> Hi,
> 
> I have an objects that when I convert to a string using __repr__
> throws a DetachedInstanceError. If I access any of their members or
> test the session (using 'user in Session') everything is fine but if I
> check 'self in Session' in __repr__ the result is False.
> I can reattach it to the Session using merge, inside the __repr__
> call, but every time I call repr I get the same problem.
> 
> I'm using PostgreSQL 8.4 and SqlAlchemy 0.6.4 and I'm using Pylons
> 1.0. I have a nested transaction (using Session.begin_nested) that is
> updating objects that are attached to a User object but that don't
> change the user object itself but the problem is seen in other,
> unrelated objects. Other than the nested transaction there are no
> other flushes or commits.
> 
> Does anybody have any idea what is going on?

if you're doing any session.close() or session.expunge(), whatever references 
you have left after that aren't in the session.  that's the only way you can 
end up with detachment errors.  also, pulling objects in and out of caches, 
across processes with pickle, stuff like that, can introduce detached objects.  
 merge() doesn't reattach objects either it returns a new object that is 
associated with the session.  the one you send stays detached (if it was 
already).


> 
> Thanks,
> 
> Ben
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalchemy@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.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@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