Sujet : Re: psycopg2 positioning of .commit() (Posting On Python-List Prohibited)
De : Karsten.Hilbert (at) *nospam* gmx.net (Karsten Hilbert)
Groupes : comp.lang.pythonDate : 09. Sep 2024, 18:28:23
Autres entêtes
Message-ID : <mailman.2.1725902905.31645.python-list@python.org>
References : 1 2 3 4 5 6 7 8 9 10 11
Am Mon, Sep 09, 2024 at 10:00:11AM -0000 schrieb Jon Ribbens via Python-list:
The database only needs to commit when it is explicitly told. Anything
less -- no commit.
>
So the Python code is half-way through a transaction when it throws
a (non-database-related) exception and that thread of execution is
aborted. The database connection returns to the pool, and is re-used
by another thread which continues using it to perform a different
sequence of operations ... ending in a COMMIT, which commits
one-and-a-half transactions.
Right, but that's true only when writable connections are
being pooled, which should be avoidable in many cases.
Any pool worth its salt should rollback any potentially
pending transactions of a connection when it is given back
that pooled connection. Unless explicitely told not to.
Karsten
-- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B