[sqlalchemy] Re: DetachedInstanceError after transaction
my stuff doesn't handle the transaction commit - that's purely transaction / pyramid_tm so i'll look into that code to see if its closing it. great lead, thanks. -- 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.
Re: [sqlalchemy] Re: DetachedInstanceError after transaction
Hi Jonathan, It's pyramid_tm -- it will clear the session on commit. It's counter-intuitive (or at least it was for me) if you've spent a lot of time with SQLAlchemy and using sessions directly, but you should try flush instead of commit: print userInstance.id DBSession.flush() print userInstance.id Then your view will still have access to the userInstance object after adding/updating it, but pyramid_tm to commit the transaction for you. I know there's been a lot of discussion about this and there are many other ways of handling it, but from the perspective of porting Pylons to Pyramid + pyramid_tm, swapping out commit() for flush() covers a lot of cases and still lets you handle IntegrityError and other exceptions. We should probably move this to the Pylons/Pyramid list if there are more questions though. Hope this helps! Eric On Tue, Feb 14, 2012 at 2:09 PM, Jonathan Vanasco jonat...@findmeon.comwrote: my stuff doesn't handle the transaction commit - that's purely transaction / pyramid_tm so i'll look into that code to see if its closing it. great lead, thanks. -- 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.
[sqlalchemy] Re: DetachedInstanceError after transaction
that seems to be it... when you commit, there is a call to _finish() http://www.zodb.org/zodbbook/transactions.html#commit _finish() is documented under abort() http://www.zodb.org/zodbbook/transactions.html#abort and it includes a session.close() -- 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.
[sqlalchemy] Re: DetachedInstanceError after transaction
could anyone point in the right direction to either: 1. rebind an object to a new session or 2. allow objects to still be 'read' in the detached state ? -- 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.
[sqlalchemy] Re: DetachedInstanceError after transaction
eric- thanks. I'll post a followup on the pylons list. i've already got a call to session.flush() the problem is that i need the transaction itself committed in this block. i have a series of database transactions that happen within the request. the first database transaction should error out on a fail and it's very important to save that information for perpetuity. subsequent database transactions could fail , and are just hidden. it sounds like the design of pyramid_tm is one transaction per request, which is really weird. -- 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.
Re: [sqlalchemy] Re: DetachedInstanceError after transaction
On Tue, Feb 14, 2012 at 7:19 PM, Jonathan Vanasco jonat...@findmeon.com wrote: could anyone point in the right direction to either: 1. rebind an object to a new session or 2. allow objects to still be 'read' in the detached state ? Eric said it best: replace commit with DBSession.flush() -- 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.
Re: [sqlalchemy] Re: DetachedInstanceError after transaction
Jonathan, You probably want transaction.savepoint() in that case. There's a pretty extensive discussion here showing savepoints (and rollbacks to savepoints) as a way of creating sub-transactions with pyramid_tm: https://groups.google.com/d/msg/pylons-discuss/5Mj4R3YMXhI/GVFj2Du33JAJ You can of course do all of that in SQLAlchemy without pyramid_tm doing it for you, so if the savepoints don't cover your use cases that's something to consider. -Eric On Tue, Feb 14, 2012 at 2:24 PM, Jonathan Vanasco jonat...@findmeon.comwrote: eric- thanks. I'll post a followup on the pylons list. i've already got a call to session.flush() the problem is that i need the transaction itself committed in this block. i have a series of database transactions that happen within the request. the first database transaction should error out on a fail and it's very important to save that information for perpetuity. subsequent database transactions could fail , and are just hidden. it sounds like the design of pyramid_tm is one transaction per request, which is really weird. -- 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.