MagicStack / MagicStack/asyncpg
[BUG] Bare connections cannot be used as context managers
還沒有人認領這個 Issue。
- 主要語言
- 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:
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:
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).
貢獻指南
這個儲存庫沒有索引到貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 asyncpg.connect 入口開始,將其傳回的 connection 與 issue 中所示的 pool 和 pool.acquire context-manager 行為進行比較。驗證 bare connection 預期的 async with 生命週期,並為回報的範例新增針對性的 coverage;當範例進入和結束時不會發生 AttributeError,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- postgresql, python
- 領域
- databases
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100