3 ms·
If you're using a connection pooler with Django — or really, anything SQL database related in Python — please be mindful that the Python DB API is implicitly tr
by rosser 14y ago
If you're using a connection pooler with Django — or really, anything SQL database related in Python — please be mindful that the Python DB API is implicitly transactional. That is, if you say:
SELECT COUNT(*) FROM users;
DBAPI says:
BEGIN;
SELECT COUNT(*) FROM users;
...and leaves the COMMIT or ROLLBACK of that transaction up to you.
Aside from the severe risk of resource leaks, that has implications for which pooling modes you can use. Particularly, you can't use statement-level pooling, and unless you're scrupulous about managing those implicitly created transactions, transaction-level pooling is pretty much the same thing as connection-level pooling.
Adjust your expectations accordingly, or turn on auto-commit.
(EDIT: clarification.)
- zzzeek 14y agothe SQLAlchemy connection pool (which is what this is using) calls connection.rollback() when the connection is checked back in. as far as "leaking" transactional state it's not different from "autocommit", which is what Postgresql connections normally do (and what psycopg2 will do if you set `connection.autocommit=True`).