Chris Withers wrote:
> Do you have any good examples of both of these patterns for the hard of
> thinking? (ie: me!)
>
> The problem is that session2 (and it's engine) are only created in a
> small part of the code, while session1 is created in a much wider
> encompassing framework. As such, there's no obvious way to get session1
> to the piece of code that calls commit on session2.
>
>
> Creating both engines in the outer loop doesn't feel right, since the
> engine for session2 is only going to be used for one type of batch job,
> of which there are many more that won't use it at all...

I've never actually used two phase transactions myself.   But the idea is
to get your two pieces of the puzzle working together.   Using the
sessions separately is fine, something just needs to mediate the bigger
picture using them both.   But you could also bind your second engine into
the app-wide session too.   Or build a third session with both engines
temporarily - if your major session is contextual you could patch it in.

> (an aside: what happens here, assuming the first of your possibilities:
> session1.commit()
> raise RuntimeError('something goes bang')
> session2.commit())

session1's data would be fully committed.  session2's commit never gets
reached.   the point of prepare() is so that all involved transactions hit
a point of "OK I'm definitely good to go" first, then the commits happen.


>
> Chris
>
> --
> Simplistix - Content Management, Batch Processing & Python Consulting
>             - http://www.simplistix.co.uk
>
> --
> 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.
>
>

-- 
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