Daniele Varrazzo [Sat, 22 Feb 2025 14:00:38 +0000 (15:00 +0100)]
chore: rename tools/build library "ci"
The name `build` is problematic because we typically want to avoid tools
to go exploring them (mypy, isort, black...) but this leaves this
directory unexplored.
Daniele Varrazzo [Fri, 21 Feb 2025 16:27:29 +0000 (17:27 +0100)]
fix(pool): check that there is some connection in the pool before shrinking
There is a race condition between shrinking the pool and closing an
expired connection which might result in attempting to pop from the
empty _pool deque. Add a check to prevent that.
The bug is not serious as it doesn't compromise the pool working but it causes
noise in the logging.
perf(uuid): speed up UUID creation using a writable subclass
Introduce an object memory-compatible with UUID, but writable. Try to
create this object in the fastest possible way: calling __new__ and
setting its attributes. Then replace the class with the standard UUID.
Daniele Varrazzo [Thu, 13 Feb 2025 17:44:32 +0000 (18:44 +0100)]
ci(crdb): enable back crdb 25.1 tests
Test were failing because of the setting 'autocommit_before_ddl' now
defaulting to 'on'. After exchanging with CRDB developer, this seems the
correct behaviour for their database moving on.
Daniele Varrazzo [Fri, 10 Jan 2025 14:17:01 +0000 (15:17 +0100)]
refactor: don't keep the notifiers backlog handler in the connection state
Just keep the queue in the state and special-case its handling in the
`_notify_handler` connection method instead of registering a standard handler.
Set the queue to None to signify that we are in the `notifies()` generator.
This way we don't need the awkward weak-self + class method to avoid a
reference loop and to dereference the connection weak reference another
time, as we just did in `_notify_handler()`. Setting the queue to None
also feels cleaner than adding/removing the handler.
test: add test to verify that a server disconnection now raises AdminShutdown
Previously it was raising OperationalError, but this was just the result
of the issue reported in #988. Note that AdminShutdown is a subclass of
OperationalError, therefore this change is backward compatible.
fix(c): don't clobber an error from the server with a server disconnection
Instead of raising the exception here, return the result and let the
caller handle the exception. This might make code paths more uniform and
helps the C implementation, because we actually never call
`error_from_result()` in the Cython code.
fix: don't clobber an error from the server with a server disconnection
The server error is assumed to contain more information, as it is
returned as a result, whereas a communication error caused by a server
disconnection will only make available the error message.
Close #988 (but we need to fix the Cython side too).
docs: improve organization of adaptation objects docs
Move the life cycle section above the examples, closer to the
configuration top section; explain better how `format` affects the
loader used, highlight better the connection between the protocols
defined in the `abc` module and the abstract base classes in the `adapt`
module.
The meaning of `Loader.format` wasn't explained anywhere: see #990.
Daniele Varrazzo [Fri, 27 Dec 2024 02:30:28 +0000 (03:30 +0100)]
lint: add typing annotations to pass pre-commit
Pre-commit seems to run mypy in parallel batches, each with about 20
files. In this mode, certain tests that pass when running mypy all in
once or file-by-file, fail.
In the current state, both running mypy without arguments or running it
in pre-commit seem to work.
Daniele Varrazzo [Fri, 27 Dec 2024 01:44:43 +0000 (02:44 +0100)]
chore: ignore certain files from mypy linting
Something weird happens. Certain files pass mypy lint on their own, but
not in combination. This is mostly related to `psycopg/pq/pq_ctypes.py`
and `psycopg/pq/_pq_ctypes.py`. This problem seems largely related to
incomplete ctypes definitions.
Daniele Varrazzo [Sat, 21 Dec 2024 01:16:57 +0000 (02:16 +0100)]
fix: don't lose notifications between notifies() calls
This allows to stop periodically the generator to run some queries (for
example to LISTEN/UNLISTEN certain channels) and start the generator
again without fearing to lose notification in the window.