[sqlalchemy] Keeping soft deletion atomic in spite of model methods calling commit

2012-12-19 Thread charlax
Hi, I'm trying to implement soft deletion in my app. I'd like to keep things atomic so that if an error happens during the soft deletion process, I don't get half deleted stuff. Here is a simplified view of my code (full working example here: https://gist.github.com/4329926): class

Re: [sqlalchemy] SQLAlchemy ORM instances and direct __dict__ access

2012-12-19 Thread Michael Bayer
I'd look at the python stdlib for examples, pickle uses __getstate__ and __setstate__ (or sometimes __reduce__), copy I think uses __copy__, etc. So per class hooks are one way, the other is to pass a serializer into the target library, like: mylibrary.serialize(object,

Re: [sqlalchemy] Keeping soft deletion atomic in spite of model methods calling commit

2012-12-19 Thread Michael Bayer
On Dec 19, 2012, at 4:29 AM, charlax wrote: So the problem here is that the rollback does nothing, because there's a commit in the delete_password method (in this example there's only method called, in reality I have multiple methods). I think having stuff being committed in a model's

[sqlalchemy] How to tell in advance if session.flush() will do anything?

2012-12-19 Thread Russ
I've got some code where I want to assert that the ORM session is perfectly clean. ie: I want to know if a flush() will emit SQL. What is the best way to determine this? Right now I'm simply checking like this: if session.new or session.dirty or session.deleted: print flush() actions

Re: [sqlalchemy] How to tell in advance if session.flush() will do anything?

2012-12-19 Thread Michael Bayer
On Dec 19, 2012, at 12:21 PM, Russ wrote: I've got some code where I want to assert that the ORM session is perfectly clean. ie: I want to know if a flush() will emit SQL. What is the best way to determine this? Right now I'm simply checking like this: if session.new or session.dirty

Re: [sqlalchemy] How to tell in advance if session.flush() will do anything?

2012-12-19 Thread Russ
On Wednesday, December 19, 2012 12:29:50 PM UTC-5, Michael Bayer wrote: the Session uses the method session._is_clean() internally to check if going through the flush() steps is warranted, which is roughly equivalent to the check you're doing, though it is doing less work to make this

Re: [sqlalchemy] pyodbc connections string with DSN and autocommit Help Please!

2012-12-19 Thread ScottyMac
Michael, It definitly is not MSSQL - I picked that up from somewhere out there on the internet. I am trying to access quickbooks enterprise and it is quickbooks proprietary database I am using Qodbc for the quickbooks connector and pyodbc as the python connector. Also, Table Reflection is

Re: [sqlalchemy] pyodbc connections string with DSN and autocommit Help Please!

2012-12-19 Thread Michael Bayer
there's many levels this could be failing, and the first step would be to make a raw PyODBC connection to the database, to see if there's any incompatibilities there. here's all the detail on how to do that: http://code.google.com/p/pyodbc/wiki/ConnectionStrings its possible the

Re: [sqlalchemy] How to tell in advance if session.flush() will do anything?

2012-12-19 Thread Russ
Whoops - _is_clean() doesn't make it up to a ScopedSession... Digging into why this is the case I see the registry pattern in there. Is it a safe/valid cheat to access the registry directly and do this? if my_scoped_session.registry()._is_clean(): print an attempt to modify the session was

Re: [sqlalchemy] How to tell in advance if session.flush() will do anything?

2012-12-19 Thread Michael Bayer
On Dec 19, 2012, at 1:22 PM, Russ wrote: Whoops - _is_clean() doesn't make it up to a ScopedSession... Digging into why this is the case I see the registry pattern in there. Is it a safe/valid cheat to access the registry directly and do this? if

Re: [sqlalchemy] pyodbc connections string with DSN and autocommit Help Please!

2012-12-19 Thread ScottyMac
I have no problem at all with pyodbc and qodbc Here is a sample I just did: I include a call to connect without autocommit - which throws an error, and then the one what works. The error message is exactly the same one I get trying to connect SQLAlchemy. I do not know how to translate cx =

Re: [sqlalchemy] pyodbc connections string with DSN and autocommit Help Please!

2012-12-19 Thread Michael Bayer
On Dec 19, 2012, at 2:49 PM, ScottyMac wrote: I have no problem at all with pyodbc and qodbc Here is a sample I just did: I include a call to connect without autocommit - which throws an error, and then the one what works. The error message is exactly the same one I get trying to connect

Re: [sqlalchemy] pyodbc connections string with DSN and autocommit Help Please!

2012-12-19 Thread ScottyMac
On Wednesday, December 19, 2012 3:37:16 PM UTC-6, Michael Bayer wrote: On Dec 19, 2012, at 2:49 PM, ScottyMac wrote: I have no problem at all with pyodbc and qodbc Here is a sample I just did: I include a call to connect without autocommit - which throws an error, and then the one what

Re: [sqlalchemy] pyodbc connections string with DSN and autocommit Help Please!

2012-12-19 Thread Michael Bayer
On Dec 19, 2012, at 5:10 PM, ScottyMac wrote: On Wednesday, December 19, 2012 3:37:16 PM UTC-6, Michael Bayer wrote: On Dec 19, 2012, at 2:49 PM, ScottyMac wrote: I have no problem at all with pyodbc and qodbc Here is a sample I just did: I include a call to connect without autocommit