Daniele Varrazzo [Mon, 27 Jun 2022 21:32:20 +0000 (22:32 +0100)]
fix: clean internal use of LiteralString
Tested one-off using pyre 0.9.13; however it gives too many differences
compared to mypy to use it at the moment.
The pyre run doesn't currently find LiteralString-related problems,
except the todo at psycopg/sql.py:251, because string.Formatter.parse()
doesn't return a LiteralString upon LiteralString input.
feat: don't block on address resolution in async connections
Use the same algorithm implemented in the `_dns` module, but based on
asyncio getaddrinfo: this avoids the need of the external dns package
and works correctly with the /etc/hosts file.
There were problems of resource leaking in Python 3.6, but as psycopg
3.1 is 3.7+ only, let's go for it!
Daniele Varrazzo [Sun, 12 Jun 2022 09:09:42 +0000 (11:09 +0200)]
fix: sync pipeline before rollback()
We were syncing it already, but only if we had received a "pipeline
aborted" already. This might be not the case, as probably the tests
test_errors_raised_on_commit which has been failing in CI randomly for
weeks has been trying to say. Other similar branches (e.g. on commit)
don't have the same check for aborted state.
fix: produce consistent error messages on date overflow
- State if the date is too small or too large, not just "not supported".
- Use similar messages in text and binary format.
- Avoid an overflow error with the infinity date in Python.
refactor: rename the no_pqexec param to force_extended
This refers to using the extended query protocol even in cases where the
singe query protocol might have been chosen instead (e.g. because we
don't have parameters to send).
The negative in the param name is confusing, and the reference to the
PQexec function is wrong, because we never use that function (which is
blocking), but rather we choose PQsendQueryParams instead of
PQsendQuery.
There is no reason to use it: the only reason to not use
PQsendQueryParams is to send multiple statements, but this is not
possible in pipeline mode anyway.
Using PQsendQuery seems to produce a spurious Close message, which the
libpq is surprised to receive. Issue reported to pgsql-bugs.
Denis Laxalde [Wed, 25 May 2022 06:51:05 +0000 (08:51 +0200)]
fix: sync nested pipeline with pending commands upon enter
When entering a nested pipeline and the outer one has pending commands,
we now sync the pipeline. This is probably less surprising at it makes
the implicit transaction from a nested pipeline isolated from the outer
one.
With this, the explicit Sync when entering a transaction is no longer
needed.
Daniele Varrazzo [Sun, 22 May 2022 00:08:03 +0000 (02:08 +0200)]
fix: don't add a cast to text literals
Normally cast is not added to unknown literals, and the text oid is not
usually used. However, when it is, it causes problems. Often Postgres
wants just a literal, not a cast type; for instance, this is not valid:
Daniele Varrazzo [Thu, 19 May 2022 21:41:26 +0000 (23:41 +0200)]
Test: fix mypy 0.941 run
This seems a mypy shortcoming fixed in 0.950 as the CI didn't complain.
The row factory definition was exotic but arguably correct. Not worth
bumping up the min version for it anyway.
Denis Laxalde [Mon, 16 May 2022 17:16:53 +0000 (19:16 +0200)]
fix: only use covariant Row type variable
The real variance of Row type variable is covariant, per definition of
RowMaker (RowMaker[B] is a subtype of RowMaker[A] if B is a subtype of
A; similar to the Box type in [mypy documentation][]).
By dropping the Row type variable from Cursor argument in RowFactory, we
are now able to only use the covariant Row variable (previously Row_co,
now Row). Indeed, RowFactory does not actually depend on Cursor on being
parametrized on Row; rather it's the other way around (Cursor's Row type
variable comes from its row factory).
Denis Laxalde [Sun, 15 May 2022 12:28:36 +0000 (14:28 +0200)]
fix: use a more generic connection type in {Client,Server}Cursor
This makes them similar to plain Cursor class, i.e. being parametrized
on sync or async connection type, not the row type (which is handled
through the second type variable).
Daniele Varrazzo [Sat, 14 May 2022 08:22:44 +0000 (10:22 +0200)]
fix: don't barf on errors with blank sqlstate
Such messages are not entirely valid (sqlstate is documented to be
always present), however we receive them after a SHOW HELP in the
PgBouncer admin database.
The SHOW HELP actually does generate a sqlstate `00000` but the message
is somehow parsed incorrectly by the libpq, which goes on to report an
error:
message contents do not agree with length in message type "N"
See #303. PgBouncer issue reported upstream in
https://github.com/pgbouncer/pgbouncer/issues/718
Daniele Varrazzo [Thu, 12 May 2022 22:16:13 +0000 (00:16 +0200)]
test: disable tests throwing copy to executemany in client-side cursors
The async one sometimes gets in an allocation loop. On my laptop it gets
OOM'd quickly. On Github Actions it might be the cause of test taking an
unusually long time.
Daniele Varrazzo [Thu, 12 May 2022 21:47:46 +0000 (23:47 +0200)]
fix: don't forbid all PQexec queries in client-side cursors
We can still use PQexecParams with an empty list of parameters. This has
advantages, such as the possibility of implementing stream(), and less
faffing with differences between Cursor and ClientCursor.
Daniele Varrazzo [Sat, 14 May 2022 22:24:17 +0000 (00:24 +0200)]
test: skip testing random multirange arrays with empty last elements
Previously we were skipping the ones with an empty first element,
because of a known shortcoming in finding the right OID. Now that we
scan the whole array to find all the elements' classes, it's the last
entry which might break dumping.
Daniele Varrazzo [Fri, 13 May 2022 14:54:54 +0000 (16:54 +0200)]
fix: raise DataError if IntDumper tries to dump another type
Allow to dump int subclasses, but not other numeric type, which can lead
to truncation. As seen in #301, the Python implementation truncates; the
c implementation is reporting failing with a TypeError, but on Python
3.8 it raises a deprecation warning instead.
The condition largely happens dumping array of mixed types. However we
should probably test with array of mixed class in a more generic way.