MagicStack / MagicStack/asyncpg

Add support for PGOPTIONS environment variable

オープン
#1,070 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
8.1k
フォーク
468
PR マージ指標
30日以内にマージされた PR はありません

説明

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
```

https://www.postgresql.org/docs/current/libpq-envars.html

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

既存の PG 環境変数が読み取られている asyncpg/connect_utils.py から始め、要求された動作を PostgreSQL の libpq 環境変数に関するドキュメントと比較します。PGOPTIONS を設定して、提供されている再現コード test_asyncpg_timeout.py を実行してください。PGOPTIONS の値がサーバー設定として解釈され、statement_timeout の例が psql と同じように動作すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
postgresql, python
領域
databases
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
52/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。