MagicStack / MagicStack/asyncpg

[BUG] Bare connections cannot be used as context managers

オープン
#583 コメント 2 件 リアクション 24 件 担当者 0 名 GitHub で見る

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

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

説明

* **asyncpg version**: 0.20.1
* **PostgreSQL version**: 10.3
* **Python version**: 3.8.2
* **Platform**: Windows
* **Do you use pgbouncer?**: No
* **Did you install asyncpg with pip?**: Yes

While under most use cases, people will want to use connection pools to manage their connections, there are times where using bare connections turns out to be more practical. However, while connection pools can be opened and closed via context managers:

```py
async with asyncpg.create_pool(user='postgres', command_timeout=60) as pool:
async with pool.acquire() as con:
await con.fetch('SELECT 1')
```

...it appears that bare connections created via `asyncpg.connect` do not support this:

```py
async with asyncpg.connect(user='postgres') as con:
await con.fetch('SELECT 1')
```

```
File "./test.py", line 120, in fetch_ip_list
async with asyncpg.connect(user="postgres") as con:
AttributeError: __aexit__
```

I personally like using `with` blocks to handle the scope of resources like this, so this is a step down for me in terms of ergonomics, not to mention rather surprising given that connections coming from connection pools do work as context managers (even though those are merely returned to the pool instead of closed).

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

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

はじめの一歩

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

調査の方向性

asyncpg.connect のエントリーポイントから始め、issue に示されている pool と pool.acquire のコンテキストマネージャーの動作を、返された接続と比較します。単独の接続に対して期待される async with のライフサイクルを検証し、報告された例を対象とする集中的なカバレッジを追加します。例が AttributeError なしで開始・終了できれば完了です。

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

評価

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

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

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