On Aug 10, 2010, at 12:38 AM, Jon Nelson wrote:
> On Mon, Aug 9, 2010 at 11:27 PM, Michael Bayer <[email protected]>
> wrote:
>>
>> On Aug 10, 2010, at 12:03 AM, Jon Nelson wrote:
>>
>>> I tried setting isolation_level to SERIALIZABLE in my create_engine
>>> options, while using psycopg2.
>>> However, an strace clearly shows that it is using READ COMMITTED.
>>> Is setting the isolation_level not supported with psycopg2?
>>
>>
>> Here's a test:
>>
>> eng = create_engine('postgresql://....', isolation_level='SERIALIZABLE',
>> echo=True)
>> print eng.execute('show transaction isolation level').scalar()
>>
>> for me it returns 'serializable'.
>
> Aha, but in psycopg2, transactions ALWAYS get a new transaction level
> (set on the psycopg2 connection object with set_isolation_level). Add
> to the above:
can you try this patch and let me know it does everything you need:
diff -r 753e46f6868c lib/sqlalchemy/dialects/postgresql/psycopg2.py
--- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py Mon Aug 09 20:32:37
2010 -0400
+++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py Tue Aug 10 09:49:32
2010 -0400
@@ -208,7 +208,20 @@
return psycopg
def on_connect(self):
- base_on_connect = super(PGDialect_psycopg2, self).on_connect()
+ if self.isolation_level is not None:
+ extensions = __import__('psycopg2.extensions').extensions
+ isol = {
+ 'READ_COMMITTED':extensions.ISOLATION_LEVEL_READ_COMMITTED,
+ 'READ_UNCOMMITTED':extensions.ISOLATION_LEVEL_READ_UNCOMMITTED,
+ 'REPEATABLE_READ':extensions.ISOLATION_LEVEL_REPEATABLE_READ,
+ 'SERIALIZABLE':extensions.ISOLATION_LEVEL_SERIALIZABLE
+
+ }
+ def base_on_connect(conn):
+ conn.set_isolation_level(isol[self.isolation_level])
+ else:
+ base_on_connect = None
+
if self.dbapi and self.use_native_unicode:
extensions = __import__('psycopg2.extensions').extensions
def connect(conn):
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.