Re: best way to handle IntegrityError with pyramid_tm

2011-05-16 Thread Eric Rasmussen
Thanks Michael -- I had a feeling it was something simple eluding me.
Calling Session.flush() worked perfect.

On Mon, May 16, 2011 at 4:26 PM, Michael Merickel wrote:

> 2) Return a newly committed object (for instance, if I save a new user
>> successfully, I'd like to return that user object to the handler)
>
>
> You can populate your user object's pkey same as always by issuing a
> session.flush() after adding the object to your session. This will dump it
> to the database, populate the pkey, and refresh the orm object. The data is
> not persisted until you commit the session using transaction.commit() or
> allowing pyramid_tm to issue the commit for you at the end of the request.
>
> This may passively answer your previous question, but maybe not. In general
> if you're worried about integrity errors you can probably just issue a flush
> (which executes the SQL in the db) and see if that works.
>
> One question I cannot answer, however, is how the transaction manager
> interacts with nested transactions. Anyone have an answer for this?
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To post to this group, send email to pylons-discuss@googlegroups.com.
> To unsubscribe from this group, send email to
> pylons-discuss+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.
>

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



Re: best way to handle IntegrityError with pyramid_tm

2011-05-16 Thread Michael Merickel
>
> 2) Return a newly committed object (for instance, if I save a new user
> successfully, I'd like to return that user object to the handler)


You can populate your user object's pkey same as always by issuing a
session.flush() after adding the object to your session. This will dump it
to the database, populate the pkey, and refresh the orm object. The data is
not persisted until you commit the session using transaction.commit() or
allowing pyramid_tm to issue the commit for you at the end of the request.

This may passively answer your previous question, but maybe not. In general
if you're worried about integrity errors you can probably just issue a flush
(which executes the SQL in the db) and see if that works.

One question I cannot answer, however, is how the transaction manager
interacts with nested transactions. Anyone have an answer for this?

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



best way to handle IntegrityError with pyramid_tm

2011-05-16 Thread Eric Rasmussen
Hi everyone,

I'm still coming to terms with the concept of a transaction manager (I'm
using Pyramid/Akhet), and I'm not seeing a simple and universally accepted
way doing two things I'd often do in Pylons:

1) Catch and handle SQLAlchemy exceptions like IntegrityError
2) Return a newly committed object (for instance, if I save a new user
successfully, I'd like to return that user object to the handler)

Can someone point me in the right direction or give me any insight on how
this should work with pyramid_tm? Also, if there are any form handling
utilities that work with Pyramid/pyramid_tm and help with this, I'm
definitely interested (I still haven't settled on a form library to use with
Pyramid and Akhet).

Thanks!
Eric

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