On 11/16/2015 07:38 AM, Donald Stufft wrote:
> I am currently using the SQLAlchemy ORM and I'd like to be able to start
> up transactions using PostgreSQL's SERIALIZABLE READ ONLY DEFERRABLE
> isolation level. I don't want every single transaction to use this
> isolation level nor do I have the ability to change the server
> configuration so I need to do it in my application. My question is, what
> is the best way to go about achieving this? I tried setting the
> execution_option to "SERIALIZABLE READ ONLY DEFERRABLE" but that fails
> with the error message of "Valid isolation levels for postgresql are
> REPEATABLE READ, AUTOCOMMIT, SERIALIZABLE, READ COMMITTED, READ
> UNCOMMITTED".
so the built-in way to do one-offs like these w/ an ORM session is like
this:
conn = session.connection()
conn.detach()
conn.execute("set session isolation <whatever>")
< work with connection>
what detach() does means it's going to throw away the DBAPI connection
when we're done with it, it won't be used again. This might be all you
need, or then you might need to do this a lot and don't want to degrade
the efficiency of the connection pool.
The other way public-API wise is to use events, e.g. like checkin
events, to reset the isolation level when the connection comes back to
the pool. There's some internal systems that do this also which I'm
sure you've noticed, poking around at them I think the idea of a way to
add custom ad-hoc isolation settings which get reset by the usual
"reset_isolation_level" hook might be handy. I'm still underwater
with work meetings all week this week so if you can ping me w/ the code
you were working on towards the end of the week maybe we can look at
that possibility.
>
> --
> You received this message because you are subscribed to the Google
> Groups "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected]
> <mailto:[email protected]>.
> To post to this group, send email to [email protected]
> <mailto:[email protected]>.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.