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.
Denis Laxalde [Mon, 6 Dec 2021 07:44:02 +0000 (08:44 +0100)]
Add a --pq-tracefile pytest option
When specified, we'd enable tracing of the client/server communication
to a file. The file is opened for the whole test session and we set a
title section before each test run.
Denis Laxalde [Fri, 3 Dec 2021 07:05:16 +0000 (08:05 +0100)]
Add bindings for PQ tracing functions
Since we cannot pass a file descriptor as a FILE value, as expected by
PQtrace(), PGconn.trace() method accepts a 'fileno: int' value. This is
then used to build an stdio's FILE value through fdopen(). The latter
also needs a binding in ctypes. This only works on Linux platform.
In _pq_ctypes.pyi, fdopen() and PQtrace() are not autogenerated because
of the needed '# type: ignore' (similar to existing ones).
PQsetTraceFlags() is new from libpq 14, so we declare it conditionally.