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 上下文管理器行为进行比较。验证 bare connection 预期的 async with 生命周期,并为报告中的示例添加针对性覆盖;当示例进入和退出时不会出现 AttributeError,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- postgresql, python
- 领域
- databases
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100