Repository navigation
Conversation
On Windows, parse_service_info() built the service file path as
os.getenv("PGSYSCONFDIR") + "\pg_service.conf", so `pgcli service=foo`
or PGSERVICE crashed with a TypeError whenever PGSYSCONFDIR was unset,
which is the default.
Fall back to libpq's per-user service file on Windows,
%APPDATA%\postgresql\.pg_service.conf, when PGSYSCONFDIR is not set.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, this fixes the crash. Two things in the same function, in case you want to fold them in (happy to do a follow-up otherwise): libpq reads the per-user file first and only falls back to Also, with |
Read the per-user file first and fall back to $PGSYSCONFDIR/pg_service.conf when the service isn't there. The system file has no leading dot. With APPDATA unset on Windows there is no per-user file, instead of a path relative to the current directory.
|
Good catches, thanks! Folded all of it in: the per-user file comes first, then This does change one thing for existing setups: |
Description
On Windows,
pgcli service=mydb(orPGSERVICE=mydb pgcli) crashes unlessPGSERVICEFILEorPGSYSCONFDIRis set:PGSYSCONFDIRis usually unset, so the Windows branch addsNoneto a string.parse_service_infonow looks files up the way libpq'sparseServiceInfodoes:PGSERVICEFILEif set, otherwise the per-user file:%APPDATA%\postgresql\.pg_service.confon Windows (docs),~/.pg_service.confelsewhere.$PGSYSCONFDIR/pg_service.conf, with no leading dot.APPDATAunset on Windows there is no per-user file, rather than a path relative to the current directory.So
$PGSYSCONFDIRno longer wins over the per-user file, and$PGSYSCONFDIR/.pg_service.confis no longer read. libpq also falls back to a compiled-inSYSCONFDIRwhenPGSYSCONFDIRis unset, and pgcli can't know that path, so that case isn't covered.The new tests fake
platform.system()so they run on the Linux CI too. Run on Windows withpytest tests/test_main.py -k service: 13 pass, and 5 fail againstmain.Checklist
changelog.rst.AUTHORSfile (or it's already there).pip install pre-commit && pre-commit install).