Add support for PGOPTIONS environment variable
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 52/100
Research direction
Start in asyncpg/connect_utils.py, where the existing PG environment variables are read, and compare the requested behavior with the PostgreSQL libpq-envars documentation. Run the provided test_asyncpg_timeout.py reproduction with PGOPTIONS set; done means PGOPTIONS values are interpreted as server settings and the statement_timeout example behaves like psql.
Written by the indexing model from the issue text.
Description
asyncpg supports an explicit server_options=... dict connection method parameter, but does not seem to populate its value from the PGOPTIONS environment variable. This is a feature request for it to do so.
Specifically, asyncpg/connect_utils.py reads user, host, port, database, password, and SSL information with calls like os.getenv('PGUSER'), os.environ.get('PGHOST'), etc. There is no corresponding call for reading PGOPTIONS.
I would like to set the environment variable PGOPTIONS='-c default_transaction_read_only=on -c statement_timeout=120s' and have asyncpg interpret its values as server_settings the way libpq does. For instance, the below works for psql:
PGOPTIONS='-c statement_timeout=1s' psql -c "SELECT pg_sleep(2)"
ERROR: canceling statement due to statement timeout
but a simple asyncpg script running the same ignores the statement_timeout since it never reads the value of PGOPTIONS.
$ PGOPTIONS='-c statement_timeout=1s' ./test_asyncpg_timeout.py
SELECT 1
- Dominant language
- Python
- Stars
- 8.1k
- Forks
- 469
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 9
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.
More from MagicStack/asyncpg
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
MagicStack/asyncpg#1357 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
MagicStack/asyncpg#1354 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
MagicStack/asyncpg#1342 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 56/100
MagicStack/asyncpg#1340 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 28/100
MagicStack/asyncpg#1337 ·
All issues in MagicStack/asyncpg
Similar issues
-
Add: hunch Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
AbdelStark/awesome-typesafe#104 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
DiamondLightSource/dodal#2211 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
openml/openml-python#1749 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
sipyourdrink-ltd/bernstein#6191 ·