[sqlalchemy] Re: Orm models, transaction and multiple binds

2019-01-11 Thread Jonathan Vanasco
request lifecycle - https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/router.html the commit on session_2 is happening in the tween_egress, but the rendering is happening in the view_pipeline above it. i think the only way you can accomplish easily is without using the transaction manger

Re: [sqlalchemy] sqlalchemy session in same transaction as existing psycopg2 connection

2018-08-29 Thread 'Brian DeRocher' via sqlalchemy
Beautiful. Skipping the psycopg2 initialization prevents that rollback and allows SQLAlchemy to use the same transaction. FWIW, I don't think pool_reset_on_return=None is needed, at least for my purposes. Thanks for the help and thanks for the advice about raw_connection(). I'll get

Re: [sqlalchemy] sqlalchemy session in same transaction as existing psycopg2 connection

2018-08-28 Thread Mike Bayer
gt;> > I'm writing some automated tests for some legacy python code using a >> > psycopg2 connection. I'd like to check data in the database by using >> > SQLAlchemy. I rollback the database transaction after each test in >> > tearDown(). >> > >>

Re: [sqlalchemy] sqlalchemy session in same transaction as existing psycopg2 connection

2018-08-28 Thread 'Brian DeRocher' via sqlalchemy
connection. I'd like to check data in the database by using > > SQLAlchemy. I rollback the database transaction after each test in > > tearDown(). > > > > The problem is my SQLAlchemy connection doesn't see the database > updates. > > At first I thought

Re: [sqlalchemy] sqlalchemy session in same transaction as existing psycopg2 connection

2018-08-28 Thread Mike Bayer
On Tue, Aug 28, 2018 at 11:32 AM, 'Brian DeRocher' via sqlalchemy wrote: > Hey all, > > I'm writing some automated tests for some legacy python code using a > psycopg2 connection. I'd like to check data in the database by using > SQLAlchemy. I rollback the database transaction

Re: [sqlalchemy] sqlalchemy session in same transaction as existing psycopg2 connection

2018-08-28 Thread Simon King
to check data in the database by using > > SQLAlchemy. I rollback the database transaction after each test in > > tearDown(). > > > > The problem is my SQLAlchemy connection doesn't see the database updates. > > At first I thought they weren't using the same

Re: [sqlalchemy] sqlalchemy session in same transaction as existing psycopg2 connection

2018-08-28 Thread Simon King
On Tue, Aug 28, 2018 at 4:32 PM 'Brian DeRocher' via sqlalchemy wrote: > > Hey all, > > I'm writing some automated tests for some legacy python code using a psycopg2 > connection. I'd like to check data in the database by using SQLAlchemy. I > rollback the database transacti

[sqlalchemy] sqlalchemy session in same transaction as existing psycopg2 connection

2018-08-28 Thread 'Brian DeRocher' via sqlalchemy
Hey all, I'm writing some automated tests for some legacy python code using a psycopg2 connection. I'd like to check data in the database by using SQLAlchemy. I rollback the database transaction after each test in tearDown(). The problem is my SQLAlchemy connection doesn't see the database

[sqlalchemy] Re: idle in transaction

2015-02-14 Thread Jonathan Vanasco
Just to add to Michael's reply -- keep in mind that how you handle the session (commit/rollback/close) will impact the state of any objects the session loaded if you're using the ORM and that can have implications in your app. The default behavior of sessions is to have `expire_on_commit=True`

[sqlalchemy] Re: DetachedInstanceError after transaction

2012-02-14 Thread Jonathan Vanasco
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

Re: [sqlalchemy] Re: DetachedInstanceError after transaction

2012-02-14 Thread Eric Rasmussen
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()

[sqlalchemy] Re: DetachedInstanceError after transaction

2012-02-14 Thread Jonathan Vanasco
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

[sqlalchemy] Re: DetachedInstanceError after transaction

2012-02-14 Thread Jonathan Vanasco
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] Re: DetachedInstanceError after transaction

2012-02-14 Thread Jonathan Vanasco
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

Re: [sqlalchemy] Re: DetachedInstanceError after transaction

2012-02-14 Thread Claudio Freire
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() --

Re: [sqlalchemy] Re: DetachedInstanceError after transaction

2012-02-14 Thread Eric Rasmussen
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

[sqlalchemy] howto Sqlalchemy atomic transaction ??

2011-11-20 Thread sajuptpm
Hi, http://dpaste.com/659618/ -- 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

[sqlalchemy] Re: Long running transaction issues with commit

2011-06-02 Thread Aalok Sood
Hello Michael Thanks a lot for your quick response. I changed this loop to: or i in range(1000): : sleep(15) : print commiting : mm.name=u'old name' : s.commit() : sleep(25) : mm.name=u'new name' : print commiting2

Re: [sqlalchemy] Re: Long running transaction issues with commit

2011-06-02 Thread Michael Bayer
On Jun 2, 2011, at 11:35 AM, Aalok Sood wrote: Hello Michael Thanks a lot for your quick response. I changed this loop to: or i in range(1000): : sleep(15) : print commiting : mm.name=u'old name' : s.commit() : sleep(25) :

[sqlalchemy] Re: Long running transaction issues with commit

2011-06-02 Thread Aalok Sood
Yes its all so very clear now, kind of obvious :) Thank you for taking out time to help me. Regards Aalok Sood. On Jun 2, 9:20 pm, Michael Bayer mike...@zzzcomputing.com wrote: On Jun 2, 2011, at 11:35 AM, Aalok Sood wrote: Hello Michael Thanks a lot for your quick response. I

[sqlalchemy] partial rollback in transaction ?

2011-01-08 Thread Romy
This may or may not be specific to SQLAlchemy (rather than elixir), but I figured I'd ask seeing as how this list is much more active. I'm experiencing only a partial rollback in the following code -- invite_code gets incremented even when the exception is caught and session rolled back. When I

Re: [sqlalchemy] partial rollback in transaction ?

2011-01-08 Thread Michael Bayer
The rollback of attributes is actually an expiration of all mapped attributes.So used would need to be a mapped column for its value to be rolled back. Other than that, invite_code would need to be present in elixir.session for that to work, if something is causing that not to be the

[sqlalchemy] Re: InternalError: current transaction is aborted, commands ignored until end of transaction block...

2010-09-29 Thread tom
First, thanks for that quick answer, that explains it. I turned autocommit on, and it works again. That leads me to this question: I do have session.commit() sprinkled throughout my code without any except: rollback() blocks, can that lead to problems down the line? I had the impression that

Re: [sqlalchemy] Re: InternalError: current transaction is aborted, commands ignored until end of transaction block...

2010-09-29 Thread Michael Bayer
On Sep 29, 2010, at 11:03 AM, tom wrote: First, thanks for that quick answer, that explains it. I turned autocommit on, and it works again. That leads me to this question: I do have session.commit() sprinkled throughout my code without any except: rollback() blocks, can that lead to

[sqlalchemy] Re: InternalError: current transaction is aborted, commands ignored until end of transaction block...

2010-09-29 Thread tom
Thank you very much, that was very helpful! On Sep 29, 5:27 pm, Michael Bayer mike...@zzzcomputing.com wrote: On Sep 29, 2010, at 11:03 AM, tom wrote: First, thanks for that quick answer, that explains it. I turned autocommit on, and it works again. That leads me to this question: I do

[sqlalchemy] Open transaction inside transaction

2010-02-22 Thread Terminator 101
Hello, I want to know if open a transaction inside another is safe and encouraged? I have a method: def foo(): session.begin try: stuffs except Exception, e: session.rollback() raise e session.commit() and a method that calls the first one,

[sqlalchemy] Re: how to transaction like this

2009-05-21 Thread manman
thanks very much! On 5月20日, 下午9时03分, Werner F. Bruhin werner.bru...@free.fr wrote: Hi, manman wrote: yes,i known,but how do i do that? if not commit parent,how to get the parent id? flush should be enough, but I think you could also do: assuming you have a relation parent

[sqlalchemy] Re: how to transaction like this

2009-05-20 Thread kindly
Instead of the first commit use flush. You have already committed so you cant roll back. so session.begin() try: p=parent() session.add(p) session.flush() c=child() c.p_id=p.id session.add(c) session.commit() except: session.rollback() On May 20, 11:31 am,

[sqlalchemy] Re: how to transaction like this

2009-05-20 Thread manman
yes,i known,but how do i do that? if not commit parent,how to get the parent id? On 5月20日, 下午6时59分, kindly kin...@gmail.com wrote: Instead of the first commit use flush. You have already committed so you cant roll back. so session.begin() try: p=parent() session.add(p)

[sqlalchemy] Re: how to transaction like this

2009-05-20 Thread Werner F. Bruhin
Hi, manman wrote: yes,i known,but how do i do that? if not commit parent,how to get the parent id? flush should be enough, but I think you could also do: assuming you have a relation parent c.parent.append(p) or the other way round p.children.append(c) Werner

[sqlalchemy] Re: InvalidRequestError: The transaction is inactive due to a rollback... using sqlite with multiple commits.

2009-04-30 Thread Daniel
Hello Michael, Thank you for your replies. I've just tried to create a testcase but proven to myself that it does raise an exception. I'll go back and double check where I might be catching and passing on the exception. Daniel On Apr 29, 3:19 pm, Michael Bayer mike...@zzzcomputing.com wrote:

[sqlalchemy] Re: InvalidRequestError: The transaction is inactive due to a rollback... using sqlite with multiple commits.

2009-04-29 Thread Michael Bayer
Daniel wrote: I've learned a bit more. Apparently the sqlite database occasionally gets locked by another process and that lock lasts longer than the five second default timeout. SQL Alchemy quietly issues a ROLLBACK, but doesn't say anything more about it. The result is that the session

[sqlalchemy] Re: InvalidRequestError: The transaction is inactive due to a rollback... using sqlite with multiple commits.

2009-04-29 Thread Michael Bayer
how is it that you know this is due to the SQLite timeout ? did you create a test case ? creating a fully reproducible test case would be the next step. On Apr 29, 2009, at 5:15 PM, Daniel wrote: I'm not catching it or re-raising it. Where else could I look to solve this. On Apr

[sqlalchemy] Re: InvalidRequestError: The transaction is inactive due to a rollback... using sqlite with multiple commits.

2009-04-28 Thread Michael Bayer
squelching typically means one of two things. either you're doing this: try: # do stuff with session except: print error ! # .. keep going or, you are allowing concurrent access to a single session with multiple threads, one of your threads is throwing an exception (usually

[sqlalchemy] Test and rollback transaction

2009-02-01 Thread GreyBadger
Hi, In an Exception catch block, one may or may not be sure if a transaction object has had begin() called. Is it safe to blindly call rollback() on a Transaction object, or is there a way to test if a transaction is active before calling rollback() (or indeed commit!). I couldn't find anything

[sqlalchemy] Is this a transaction?

2008-10-15 Thread Heston James - Cold Beans
Quick question I hope guys. If I have an object which contains a bunch of children and cascade is set on the relationships. When I add the parent object to the session and commit it, are the children saved as part of a transaction by default? Or do I have to do something special? If I

[sqlalchemy] ProgrammingError: (ProgrammingError) current transaction is aborted, commands ignored until end of transaction block

2008-06-27 Thread Matt Haggard
I'm getting a ProgrammingError (I've pasted the last part of the traceback at the bottom of the page). The error comes from my first heavy-AJAX page in Pylons (postgres backend). If I cause too many AJAX requests at a time, or even after doing 3 non-overlapping AJAX requests, I get the error.

[sqlalchemy] Re: Replicating a transaction

2007-03-20 Thread sdobrev
On Tuesday 20 March 2007 07:47:53 Benno Rice wrote: Hi, I'm wondering if it would be possible to have a situation where transactions coming in from the ORM system could be sent to multiple database servers at once. If I were to look into adding this, where would be the best place to

[sqlalchemy] Re: Replicating a transaction

2007-03-20 Thread Michael Bayer
SessionTransaction will start transactions across any number of databases, as different engines come into its querying scope. when SessionTranasction commits, it commits all underlying transacitons. so if you want to start all transactions at once, you can create a new

[sqlalchemy] Re: Replicating a transaction

2007-03-20 Thread Michael Bayer
On Mar 20, 2007, at 11:52 AM, Michael Bayer wrote: however, this is not using two phase commit, which means that if one commit fails, all previous commit's stay committed. if you want true two phase commit I'd look into Zalchemy which has this feature. actually i should correct myself -

[sqlalchemy] Re: psycopg2 default transaction inefficiency

2007-02-12 Thread JP
Yeah, I think I explained badly. What I was trying to show with the sqlalchemy vs postgres query logs is that extra BEGIN that psycopg2 is sending before the SELECT that sqlalchemy executes. The BEGIN is implicitly added by psycopg2 because it's in its default transaction isolation state of read

[sqlalchemy] Re: psycopg2 default transaction inefficiency

2007-02-12 Thread Michael Bayer
On Feb 12, 10:30 am, JP [EMAIL PROTECTED] wrote: But It would be nice to be able to have total control over the transactional state of the connection, so that when I know that I'm just doing a select or two I don't have to have the overhead of a BEGIN that I know is useless, but as things

[sqlalchemy] Re: psycopg2 default transaction inefficiency

2007-02-12 Thread JP
like the example illustrates, there is no BEGIN being issued for every SELECT statement when using psycopg2 in non-autocommit mode, which applies to SQLAlchemy as well. therefore there is no performance bottleneck; this is a django issue only. I guess we're reading the example differently.

[sqlalchemy] Re: psycopg2 default transaction inefficiency

2007-02-11 Thread Michael Bayer
im confused. the django thread seems to be saying that it is setting psycopg2 *into* autocommit mode, which causes the problem; the default setting of autocommit for DBAPI (and maintained in SA) is False. When i wrote frameworks years ago I always thought autocommit mode was the way to go but i

[sqlalchemy] Re: InvalidRequestError: This transaction is inactive

2007-01-24 Thread Jose Soares
Jose Soares ha scritto: Michael Bayer ha scritto: not sure about that, i thought maybe the multiple flush()es are breaking something but I just added a test case and it doesnt reproduce. make sure youre on the most recent versions since that was broken a few versions back...

[sqlalchemy] Re: InvalidRequestError: This transaction is inactive

2007-01-24 Thread Michael Bayer
then its likely a threading issue. not sure what your setup is but you should make sure that the session is used in only a single thread, typically via using a thread local variable (or using SessionContext which provides this service). On Jan 24, 2007, at 8:28 AM, Jose Soares wrote:

[sqlalchemy] Re: InvalidRequestError: This transaction is inactive

2007-01-22 Thread Michael Bayer
not sure about that, i thought maybe the multiple flush()es are breaking something but I just added a test case and it doesnt reproduce. make sure youre on the most recent versions since that was broken a few versions back... --~--~-~--~~~---~--~~ You received

[sqlalchemy] Re: sessions and transaction

2006-12-02 Thread Manlio Perillo
Michael Bayer ha scritto: if the transaction fails, the session goes right back to the same state that existed before you called the flush(), as though nothing happened. With this example: trans = begin_transaction() session = ctx.current a = SomeObject(...) session.save(a) raise Exception()