instead of gettgin an error such as "COPY cannot be used with this method".
Please check https://github.com/psycopg/psycopg/issues/71#issuecomment-3393722855
for the description of the db configuration required to make this command work.
No further support for logical replication is planned at this moment, but this
change allows to play with replication without needing to go down at libpq
level to execute replication commands.
Daniele Varrazzo [Sat, 22 Nov 2025 17:06:08 +0000 (18:06 +0100)]
fix: improve set_result() proposal:
- make it async on async cursors (consistently with `results()`,
inconsistently with `nextset()`, but the latter being sync on async
cursors was a design mistake);
- raise IndexError, consistently with sequences, better error message;
- fix test, which were simply broken and the OP didn't bother to fix
them;
- documentation improved.
Daniele Varrazzo [Fri, 21 Nov 2025 10:36:39 +0000 (11:36 +0100)]
fix(pool): trap CancelledError more consistently in the pool codebase
Include also places that were left out such as the rollback and the task
scheduling.
Note that we are relaxing the exception handler we had set up to fix the
problem with cancelled clients on wait (#509): we only had to trap
CancelledError additionally but we started managing the whole
BaseException. I don't think that trapping KeyboardException or
SystemExit without re-raising is a good idea (I think that, for
robustness, we should, but then things become very verbose and not
necessarily correct).
Daniele Varrazzo [Wed, 19 Nov 2025 23:51:43 +0000 (00:51 +0100)]
fix(pool): manage CancelledError in some exception handling path
If a CancelledError was raised during check the connection would have
been lost. The exception would have bubbled up but likely users are
using some framework swallowing it because nobody reporting the "lost
connections" issue actually reported the CancelledError.
dependabot[bot] [Fri, 7 Nov 2025 11:50:14 +0000 (11:50 +0000)]
chore(deps): bump the actions group with 2 updates
Bumps the actions group with 2 updates: [pypa/cibuildwheel](https://github.com/pypa/cibuildwheel) and [actions/upload-artifact](https://github.com/actions/upload-artifact).
Updates `pypa/cibuildwheel` from 3.2.0 to 3.2.1
- [Release notes](https://github.com/pypa/cibuildwheel/releases)
- [Changelog](https://github.com/pypa/cibuildwheel/blob/main/docs/changelog.md)
- [Commits](https://github.com/pypa/cibuildwheel/compare/v3.2.0...v3.2.1)
Updates `actions/upload-artifact` from 4 to 5
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v4...v5)
Daniele Varrazzo [Mon, 27 Oct 2025 01:14:35 +0000 (01:14 +0000)]
refactor: use make_instance instead of use_keywords
This model is more similar to psycopg2 and allow more freedom to define
how to return a class. There could be a mix of positional and keyword
arguments for example.
Sean Stewart [Tue, 15 Oct 2024 21:50:51 +0000 (17:50 -0400)]
feat: support loading composite types with keyword arguments
Changes:
1. Add `KeywordComposite*` classes to support loading composite types with keyword arguments.
2. Some optimizations for the `*BinaryLoader`.
- Use a generator to unpack (oid, value) pairs.
- Use a membership check instead of `KeyError` to optimize hot loops when looking up transformers.
3. Generics for the `*InstanceLoader` so mypy can better-track output results.
---
Co-authored by Daniele Varrazzo, mostly rebasing the feature on the
refactoring happening in the composite loading in #1175 and applying
some suggested PR changes.
refactor: cleaner inheritance in record/composite loaders
- Avoid a common base class to reuse the code, use module-level
functions.
- Make the inheritance lines of text and binary loaders similar.
- Add documentation and notes.
This refactoring is in preparation of the implementation of these
loaders in C, to clarify and simplify things. See #1175.
Daniele Varrazzo [Sat, 18 Oct 2025 15:48:32 +0000 (17:48 +0200)]
fix(pool): more robust placement of reconnection attempts
The problem reported in #1176 is the close recursion already fixed.
However, because we try to reconnect before closing, we end up scheduling
a reconnection attempt for every recursion loop.
The recursion shouldn't happen anymore, but it seems more robust to
reconnect after the connection has been successfully closed, otherwise
we might end up requesting more connections than we ought (hopefully not
as dramatically as here anyway).
Jörg Breitbart [Thu, 16 Oct 2025 00:01:32 +0000 (02:01 +0200)]
perf: load results by row rather than by column
In the past we were converting results to Python tuples proceeding
column by column. The rationale was that certain overhead such as
selecting the loader was to be paid only once per column, not once per
datum.
However this analysis was dismantled in #1163, see especially the comment at
https://github.com/psycopg/psycopg/pull/1163#issuecomment-3288921422
for some benchmark comparing various conversion strategies. In the end,
the simple row-by-row loading in a single function ends up being more
performing. Performance now surpasses the one of psycopg2.
See also #1155 for an initial analysis of performance regression.
A big thank you to Jörg Breitbart (@jerch) for this improvement!
Daniele Varrazzo [Sat, 11 Oct 2025 01:26:40 +0000 (03:26 +0200)]
fix: consider a connection closed in poll() only if it's not ready too
When closing the proxy and trying to communicate, poll returns state 25
on the connection, i.e. POLLIN | POLLERR | POLLHUP. The connection is
not closed though, so we might end up in weird state ahead (e.g. connection
stuck in ACTIVE).
Because it's suggested that the connection is readable, do read from it.
Likely a proper error will be raised downstream, but we will remain in
consistent state.
Daniele Varrazzo [Sun, 12 Oct 2025 02:38:24 +0000 (04:38 +0200)]
ci: use working test server on macOS
macos-14 can use PostgreSQL 18. I saw a failure trying to use 17; not
sure if it's still there but 18 works fine, so bump.
macos-13 better says on 17. Trying to "brew update" it will pull a
version that will try to compile docbook and takes forever to install. I
understand that avoid an upgrade we get a version that has a binary
package ("bottled", in this deranged naming convention).
refactor: check for closed connection in wait functions
Catch and display errors in a more homogeneous way: if a wait function
finds a connection closed it will raise an OperationalError chained to
the OSError obtained from stat'ing the socket. Previously control would
have gone back to the generator with a read-ready state and it would
have failed on whatever libpq function would have touched the socket.
Fix the problem reported in #608 affecting the epoll wait function, for
which we opted to use the poll function instead (which, more simply,
made the closed fd easier to spot).
note that on Windows it's not possible to use os.fstat() to ckeck a
socket state, therefore make it no-op.