On Jan 3, 2013, at 10:18 PM, Ken Lareau wrote:

> I recently (today) ran into an issue that has me perplexed as to how to 
> resolve it,
> so I'm asking here to see if anyone can shed some insight.  Hopefully I can 
> ex-
> plain it clearly enough to make me not sound completely incompetent...
> 
> I currently have an application that during it's run starts a session via 
> SQLAlchemy
> to one of our databases and keeps it available until the program exits.  
> During this
> time it does multiple changes (primarily inserts and updates) to the 
> database, but
> of course nothing is actually written to the database until a commit() is 
> done.  The
> problem is that there are times when I have a single change that must be 
> available
> in the database immediately due to external resources needing to access to 
> that
> updated/new information.


for this use case you use a distinct transaction, which means a different 
Session object.  You commit() that Session when you need this short-term data 
to be exposed.

> 
> So this leads to the question: is there any way to do an 'isolated' commit 
> from
> within a session and if so, how is it done?  As an alternative, is there a 
> way to
> use temporary new sessions to accomplish the same thing?  My current use
> in my application is I have a 'Session = scoped_session(sessionmaker())' line
> in a module which I import wherever I need it (essentially as a singleton) to 
> be
> able to access the same session throughout the code.  This would of course
> need to change, at least with an application requiring such 'sub commits'.

Depending on the database in use, using low isolation levels can have the 
effect that other transactions can view "dirty reads" as the transaction 
proceeds, but this is obviously an all-or-nothing thing.    When I need certain 
resources exposed during a long running transaction, I transfer that data to a 
different Session and commit() those changes distinctly.


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