fix: preserve # in pg_service.conf passwords#1575
Open
lawrence3699 wants to merge 1 commit intodbcli:mainfrom
Open
fix: preserve # in pg_service.conf passwords#1575lawrence3699 wants to merge 1 commit intodbcli:mainfrom
lawrence3699 wants to merge 1 commit intodbcli:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates pgcli’s .pg_service.conf parsing so passwords containing # are preserved correctly (fixing #1512), aligning connect_service() behavior with psql for these values.
Changes:
- Switch
.pg_service.confparsing from ConfigObj toconfigparser.ConfigParser(interpolation=None)and preserve error line numbers by padding skipped lines. - Add a regression test ensuring
password=abc#123is passed through unchanged.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
pgcli/main.py |
Replaces the service-file parser implementation to avoid treating # as an inline comment. |
tests/test_main.py |
Adds a regression test for service passwords containing #. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+523
to
+533
| os.environ["PGSERVICEFILE"] = tmpdir.join(".pg_service.conf").strpath | ||
| cli.connect_service("myservice", None) | ||
| mock_connect.assert_called_with( | ||
| database="a_dbname", | ||
| host="a_host", | ||
| user="a_user", | ||
| port="5433", | ||
| passwd="abc#123", | ||
| ) | ||
|
|
||
| del os.environ["PGSERVICEFILE"] |
There was a problem hiding this comment.
The test manually sets/unsets os.environ["PGSERVICEFILE"] and deletes it at the end, but if an assertion fails the cleanup won’t run and can leak state into later tests. Prefer using the monkeypatch fixture (or a try/finally) to set the env var so it’s always restored.
bobo-xxx
added a commit
to bobo-xxx/pgcli
that referenced
this pull request
Apr 18, 2026
The # character was being treated as a comment delimiter by ConfigObj, truncating passwords like abc#123 to abc. Added comment_tokens=[] to disable this behavior. Fixes dbcli#1575
This was referenced Apr 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1512
The service-file parser currently uses ConfigObj, which treats
#as an inline comment in.pg_service.conf. That truncates entries likepassword=abc#123toabc, soconnect_service()passes the wrong password down to the connection layer.This switches only the
.pg_service.confparser toConfigParser(interpolation=None). It keeps the existing initial-comment skipping behavior and preserves parse-error line numbers by padding the skipped lines back before parsing.Validation:
pytest tests/test_main.py -k 'pg_service_file' -qpytest tests/test_config.py -qruff check pgcli/main.py tests/test_main.py