MagicStack / MagicStack/asyncpg
.pgpass file support handles backslash escapes incorrectly; should de-escape values
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.1k
- Forks
- 468
- PR merge metrics
- No merged PRs in 30d
Description
https://www.postgresql.org/docs/current/libpq-pgpass.html isn't fully explicit about how to handle backslash escapes in the .pgpass file, however it's reasonably clear from the phrasing that backslashes serve only to escape backslashes and colons and therefore aren't considered part of the value they're used in. E.g., a .pgpass row of …
*:*:test\:db:test\\:password from pgpass with escapes
conveys:
- a database name of
test:db, nottest\:db - a user name of
test\, nottest\\
I ran into this problem because I have a password of 4:K1…, encoded as 4\:K1…, and it works with psql but not asyncpg. Once I remove the backslash from .pgpass, it starts working with asyncpg but failing with psql.
I would've provided a failing test and even a code change, but I can't get python setup.py test or pip install -e .[test] to work in a run-of-the-mill Python 3.12 virtualenv on my run-of-the-mill MacOS.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by resolving the Python 3.12 test setup issue reported for python setup.py test or pip install -e .[test], then locate asyncpg's .pgpass handling. Add coverage for escaped colons and backslashes, and consider the issue done when those values are de-escaped consistently with psql.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100