Daniele Varrazzo [Sun, 23 Jun 2024 11:12:34 +0000 (13:12 +0200)]
fix: fix compatibility with numpy 2.0
The only meaningful code change is with the bool class, whose type name
changed from `numpy.bool_` to `numpy.bool`. Note that using `bool`
causes a FutureWarning on import for numpy > 1.20, therefore we avoid
testing it (we still successfully test the `bool_` alias).
Other changes are related to tests: certain constant aliases are no more
available, so we skip those tests conditionally to numpy version.
Pin a minimum numpy version, to make sure we test also a numpy v1.
Picking 1.18, released back in Dec 2019, as it's the first minor
version offering binary packages for Python 3.8. This min dependency will
need to be updated when dropping Python 3.8 support.
Daniele Varrazzo [Thu, 13 Jun 2024 21:09:20 +0000 (23:09 +0200)]
chore(capability): drop has_pgbouncer_prepared()
Document to use the `has_send_closed_prepared()` capability instead,
which is a necessary condition for PgBouncer support, and doesn't give
the impression to be sufficient.
fix: lock the connection during a 'notifies()' call
With the previous implementation, it was possible to sneak an execute()
while the generator is consumed. This gives the false impression that
it's possible to use the connection while listening (see #756), which is
false for reason better explored in #757.
Therefore, lock the connection while listening to notifications. If
someone wants to mix commands with listening on the same connection,
they should do it collaboratively with an adequately short notifies()
timeout.
Daniele Varrazzo [Wed, 12 Jun 2024 10:38:04 +0000 (12:38 +0200)]
feat: add get_error_message() methods
The method is available on PGconn, PGconnCancel, PGresult.
The generic function error_message() is retained only because it was
documented so we don't want to drop it. Internally only the
get_error_message() method is used.
See https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=a7be2a6c262d5352756d909b29c419ea5e5fa1d9:
> drivers built on top of libpq should expose this function and its
> use should be generally encouraged over doing ALTER USER directly for
> password changes.
The test case assumes that the role connected to postgres has CREATEROLE
rights. If this is not true, the test is skipped.
Daniele Varrazzo [Wed, 29 May 2024 19:45:57 +0000 (21:45 +0200)]
fix(copy): fix count of chars to escape
We missed to reset the number of chars to escape at every field. As a
consequence, we end up resizing and scanning all the fields after the
first one requiring an escape and allocating a bit more memory than
needed.
Daniele Varrazzo [Tue, 14 May 2024 11:18:40 +0000 (13:18 +0200)]
fix: use the simple query protocol to execute BEGIN/COMMIT out of pipeline
We started using the extended protocol in e5079184 to fix #350, but,
probably to keep symmetry, we also changed the behaviour out of the
pipeline.
This turns out to be a problem for people connecting to the PgBouncer
admin console. They can use the `ClientCursor`, which tries to use the
simple protocol as much as it can, but they currently have to use
autocommit. With this changeset autocommit shouldn't be needed anymore.
See #808.
ci(macos): test and build macOS packages on M1 runners
Separate macos runners because:
The macos-14 runner can build amd64 images, but doesn't have Python <
3.10.
The macos-12 runner can only build x86_64 images.
Run Postgres from CI rather than from cibuildwheel, as cibw won't use a
docker image on macOS anyway. It makes it more uniform w.r.t. other
runners and doesn't require a "before" script.
fix(pool): avoid possible deadlock (until timeout) on pool closing
With the previous change to avoid finding open connections in the pool
(#784), stopping the worker was moved into the critical section. This
can create a deadlock in case a worker is in the process of obtaining a
new connection, because putting it to the pool requires the lock. The
deadlock only last for the default 5s timeout passed to _stop_workers().
Solve the problem by guarding _add_to_pool() to avoid it to try to add
the connection if the pool is closed.
However, refactor the pool closing sequence too and close the workers
and other resources that now out of the state outside the critical
section to keep the operation running under lock to a minimum.
Try to fix the flakiness shown by deaf_listen() in CI. Maybe there is a
race condition in listen()/connect() but I have also seen problems
related with localhost in the /etc/hosts file and ipv6, so let's first
try this.
feat: add a timeout parameter to Connection.cancel_safe()
This will only work for PGcancelConn, i.e. libpq >= 17, or thanks to
added waiting logic in AsyncConnection's implementation; so we add a
note about the limitation in Connection's documentation.
fix: avoid explicit str() call when logging exception
This was done as paranoia check for Sentry which might uses the repr of
the exception even if we asked for `%s` and therefore might leak
secrets, but frankly it's not our responsibility.
Avoid catching NotSupported, just check for the libpq version.
Also avoid the half exception handler in `_cancel_gen()`: as in the
legacy branch, warn and ignore any error happening in the outermost
method, without adding an ignore exception policy in an implementation
method.
This method was useful before introducing cancel_safe, which is now the
function of choice for internal cancelling.
Also refactor the exception handling to account for possible errors in
`PGcancel.cancel()`, not only in `PGconn.get_cancel()`, to make sure to
not clobber an exception bubbling up with ours, whatever happens to the
underlying connection.