fix: drop string TypeAlias definitions from public modules
The definition of the aliases as strings breaks composition with other
types. For instance `DictRow | tuple` is not valid. We could ask people
to use strings on their own, but this is a regression anyway.
In this changesets only the types reasonably exposed to the public are
fixed. Others are internal and I don't think would affect anyone (or, at
least, we can ditch the blame and put it on the user...) Modules
considered to clean from string typedefs are:
Daniele Varrazzo [Sun, 23 Jun 2024 23:53:26 +0000 (01:53 +0200)]
fix: avoid to dump [multi]range as text when binary is requested
If a range has no type information (e.g. is empty and it is a base
class, not a specific range subtype), `upgrade()` would have returned a
text dumper. This would have resulted in protocol violation, such as
requesting unhealthy amount of memory to the backend... and it was
tested too!
Restoring sanity has a drawback. If we have an array of ranges, none of
which has type information, we now fail binary dumping. Previously this
worked, provided that a cast `::int8range[]` was provided, but I think
with an extreme stretch of the protocol: we were producing binary arrays
containing text representation of the ranges.
I don't think the latter is quite valid. So I have a preference for
dropping the feature in exchange of not violating the protocol. We trade
a better dumping of the basic type (an xfail less there) in exchange of
losing the ability of dumping an array of ranges, all empty, using a
cast, in binary format. Binary dump works using a subclass such as
`Int8Range` instead of `Range`.
The lost use case is so marginal that I don't feel the need to document
it. We don't even have documentation for the `Range` subclasses.
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.