This MR implements a conversion from Postgres interval to Python
following the same rule. As a consequence, the `extract('epoch' from
interval)` function now returns the same number of seconds returned by
the `datetime.timedelta.total_seconds()` of the value returned. The
difference though is that the hours shows in the seconds:
fix: fix return value of `DateFromTicks` and `TimeFromTicks`
These function are based on the return value of `TimestampFromTicks`.
Because this value returned by this function is timezone-aware and
localized to the current timezone, truncating the value (and implicitly
losing the timezone) might return the wrong result.
For example, at tick 0, in NY, it was 1969-12-31T19:00-05:00. By
truncating the timestamp on the date, the date would be the 1969-12-31
instead of the expected 1970-01-01.
This changeset actually changes `TimestampFromTicks` to return an UTC
timestamp instead of a local timestamp. We believe that this change is
not a problem because we don't change neither the type (tz-aware
datetime) nor the value of the returned object (old and new values
compare equal). An alternative would have been to decouple the Timestamp
function from the Date/Time functions, but I think it would be confusing
if the Timestamp function returned a datetime with the date in 1969 but the
Date function returned a date in 1970.
Adjust the tests to be *stricter* than before, making use of the fact
that now the output is not affected by the local timezone.
test(pool): verify the overriding of `close()` to act as `putconn()`
We would like to maintain this possibility on a best-effort basis. The
hack has been mentioned in #1046 and upstream in
https://github.com/sqlalchemy/sqlalchemy/discussions/12522 and is useful
to integrate psycopg pool with the SQLAlchemy NullPool.
chore(deps): bump the actions group with 2 updates
Bumps the actions group with 2 updates: [pypa/cibuildwheel](https://github.com/pypa/cibuildwheel) and [prefix-dev/setup-pixi](https://github.com/prefix-dev/setup-pixi).
Updates `pypa/cibuildwheel` from 2.22.0 to 2.23.2
- [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/v2.22.0...v2.23.2)
Updates `prefix-dev/setup-pixi` from 0.8.3 to 0.8.4
- [Release notes](https://github.com/prefix-dev/setup-pixi/releases)
- [Commits](https://github.com/prefix-dev/setup-pixi/compare/v0.8.3...v0.8.4)
sobolevn [Thu, 13 Mar 2025 10:40:42 +0000 (13:40 +0300)]
fix: fix `status` annotation in `connection_summary`
Currently enum names are strings, but this is being changed to become
Literal. When this will happen, the type inferred will not be valid
anymore, as we mutate it and manipulate it as string in the function.
Daniele Varrazzo [Mon, 10 Mar 2025 23:26:23 +0000 (00:26 +0100)]
test: skip target_session_attrs with libpw < 14
Only one test fails with the currently "oldest" libpq, which is 10.2,
however the docs in libpq 13 are not explicit in which modes are
supported and, afaics, 'replica' shouldn't work either.
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 [Wed, 12 Feb 2025 11:38:38 +0000 (12:38 +0100)]
ci(crdb): enable 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).
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.