From: ritojoao (@ritojoao) <noreply+ritojoao@github.com>
To: psycopg/psycopg <noreply+psycopg-psycopg@github.com>
Subject: Re: [psycopg/psycopg] PR #1496: fix: read special connection params from the pg_service file
Date: Thu, 12 Nov 2026 17:43:19 +0000
Message-ID: <gh-psycopg-psycopg-1496-c6831303425@github.com> (raw)
In-Reply-To: <gh-psycopg-psycopg-1496@github.com>
References: <gh-psycopg-psycopg-1496@github.com>
Thanks a lot, @Binary-Refinery! Running the conninfo cases on Linux with both implementations would be really helpful. Please share the results here when you have them.
In the meantime, I ran a Linux check myself, in case it helps.
**Setup:** Docker, `python:3.12`, PostgreSQL 17.11, libpq 17.11 (`pq.version()` 170011), branch at 10b8b28 (psycopg 3.3.9), installed from `./psycopg[test]` and `./psycopg_c`.
**Test suite.** I ran `tests/test_conninfo.py`, `tests/test_conninfo_attempts.py` and `tests/test_conninfo_attempts_async.py`:
| `PSYCOPG_IMPL` | Result |
|---|---|
| `python` | 116 passed |
| `c` | 116 passed |
**Precedence check.** For each case, a small script compares `get_param()` with what libpq resolves by itself: `PQconninfo()` on a raw `pq.PGconn.connect()`, with no psycopg logic involved. It checks `host`, `port`, `connect_timeout`, `load_balance_hosts` and `target_session_attrs`, then opens a real connection with `psycopg.connect()`. I got the same results with both implementations:
| Case | Result |
|---|---|
| `service=svc` only | OK |
| DSN `connect_timeout=3` beats the service file's `connect_timeout=7` | OK |
| Service file beats env (`PGHOST=nohost`, `PGCONNECT_TIMEOUT=9`) | OK |
| `PGSERVICE=svc` env, empty DSN | OK |
| `service=` in the DSN beats `PGSERVICE` | OK |
| Service with multiple hosts plus `load_balance_hosts=random` and `target_session_attrs=read-write` | OK |
| Fallback to `pg_service.conf` in the `PGSYSCONFDIR` directory | OK |
| Env only, no service | OK |
As a control, I swapped in `_conninfo_utils.py` from current master and ran the same script. It reports `host` and `connect_timeout` as unset for `service=svc`. In the "service beats env" case, connecting fails with `failed to resolve host None`, which is the behavior described in #698.