On Sep 12, 2014, at 6:45 AM, Matthijs Blaas <thijs.bl...@gmail.com> wrote:

> Ok, i found the issue!
> 
> When I tried to use pg8000 to connect to postgres i got an error: "cannot 
> insert multiple commands into a prepared statement".
> Apparently multiple queries is fine with psycopg2, but not using pg8000.
> 
> We prefix all queries because of a workaround. We handle multi-tenancy using 
> the postgres search_path, but setting the search_path once on an new 
> transaction event resulted in another issue; the search_path is sometimes 
> "lost" during requests! I can't see why exactly, but it appears sometimes 
> during a request another connection is used which doesn't fire a new 
> transaction event.. To workaround this issue, we prefix every query fired 
> with a "set search_path to <customer_schema>; <original query>" in an 
> before_cursor_execute callback.

set the search path within the connection pool using the "connect" event; all 
connections used by the pool will then have this search path setting the moment 
they connect.  Don't ever put multiple SQL expressions in a DBAPI execute (for 
this very reason - driver changes, hilarity ensues.  We are having a crisis in 
Openstack right now because they made the same mistake).

> 
> But this still leaves the strange issue where the search_path is sometimes 
> suddenly lost during requests..

no part of your code should be changing search_path - I'd grep for it.  


-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to