After getting more information about the matter and having convinced
myself that there is no need, except FOMO, to extend the copyright year
on source code, change all our entries to leave only the start year.
git ls-tree -r HEAD --name-only \
| xargs sed -i '/Copyright.*\(Varrazzo\|Psycopg\)/ s/-20..//'
This can help configuring connections to use PgBouncer. It is possible
to use the attribute in the pool kwargs, for instance, instead of using
the more complex configure callback.
Don't auto-skip pool test if import fails. This would miss serious
problems leading to the pool not being importable. If someone wants to
skip the pool tests they can use `-m 'not pool'` now.
Don't look up other modules objects in __del__ methods
The modules might have been already cleaned up during interpreted
shutdown. See <https://bugs.python.org/issue46256#msg409847> for an
explanation.
The stdlib guards against the same thing happening too. However they
take a reference in the function closure, which is stronger than what we
do. Doing so, on our strictly typed codebase, is a tedious chore, so, if
this is enough (it should be, according to the OP), I'm happy this way.
Add ConnectionTimeout subclass of OperationalError
To be used in the connection pool to detect timeout on connection.
Backported to Psycopg 3.0.8 to allow the pool 3.1 to work with it, at
least on diminished capacity (NullPool.connection() would time out only
for clients in the queue, not in case of new connection timeout).
This makes it symmetrical with close(). However it doesn't really do any
async work as it's awkward to call it from init. Something we might do,
if that will be needed, could be to start the scheduler only and use it
to schedule immediately a call to an async _open().
In the future, an anyio-based pool might instead disallow open=True on
init.
See https://github.com/psycopg/psycopg/pull/151 for some discussion
about the topic.
Denis Laxalde [Mon, 15 Nov 2021 08:13:04 +0000 (09:13 +0100)]
Add an open() method to connection pool classes
This method is responsible for setting the '_closed' attribute, which
hence now defaults to True in the base class, along with the
_sched_runner attribute, which is reset to None in close().
Denis Laxalde [Wed, 15 Dec 2021 12:57:31 +0000 (13:57 +0100)]
Keep results from all queries run through executemany()
Instead of overwriting cursor's results at each execution in
executemany() we now accumulate the results of all queries on cursor
state by turning _set_results() into _extend_results(). This way, each
result remains accessible and one can use nextset() to move from one
result to another.
A stricter definition revealed a couple of wrong usages of the mapping.
Use more consistently the higher level `conninfo_encoding()` function
instead of directly the mapping.
Use conninfo encoding to encode errors on connection
PostgreSQL returns connection errors in the encoding specified in
lc_messages (e.g. EUC-JP for a server with `lc_messages=ja_JP.EUC-JP`).
However, because we don't have a connection, the message was decoded in
the fallback utf-8.
If the client has specified a client_encoding, use it to decode the
error message. Be more lenient than usual to look up the encoding
(because it is not normalised by the server and we don't care about
performance as this only happens on error handling). As for any other
error messages, still use an error=replace policy to avoid exploding
reporting an error in the wrong encoding.
Daniele Varrazzo [Thu, 23 Dec 2021 01:36:43 +0000 (02:36 +0100)]
Schedule a daily test run and a weekly package run
This should help detecting breakages due to new depending packages. In
the future we may extend the tests to run on Python/Postgres master
branch too.
The intention is to remove the top bound from dependency packages,
because the practice is widely documented to be problematic. Thankfully
we have only dev/test dependencies, but I'd rather get the habit for
good.
This commit will be merged on master as it is because otherwise Github
won't pick the change.
Daniele Varrazzo [Wed, 15 Dec 2021 00:24:28 +0000 (01:24 +0100)]
Reuse fixture across test module
The fixture is duplicated. Funnily enough, the dupe in async is less
efficient than the one in the sync test module, but it allowed to spot
the bug at the previous commit, after using it more than the prepared
threshold.
Daniele Varrazzo [Tue, 14 Dec 2021 23:57:11 +0000 (00:57 +0100)]
Fix prepared statements clearing
In the conditions illustrated by the test, i.e. with some statements
already prepared and a multiple statements query containing a DROP, the
check for multiple statements wouldn't have been triggered, and the
query would have eventually been asked for preparation, failing because
containing multiple statements.
Raise ProgrammingError on out-of-order exit from transactions
Previously it would have failed an assert.
Further back in time, the condition was checked and reported as
ProgrammingError already. The check was dropped when
`conn.transaction()` started to return an entered transaction, so the
possibility of calling enter/exit manually was taken out of the public
API. However, we didn't consider the possibility of concurrent
threads operating on transaction independently.
Also fix the Transaction representation, which wouldn't have reported
`(terminated)` exiting on rollback, but only on commit.