MagicStack / MagicStack/asyncpg
[BUG] Bare connections cannot be used as context managers
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 8.1k
- Fork
- 468
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
- 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).
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu từ điểm vào asyncpg.connect và so sánh connection được trả về với hành vi của pool và context-manager pool.acquire được thể hiện trong issue. Xác minh vòng đời async with dự kiến đối với một bare connection và bổ sung coverage tập trung cho ví dụ được báo cáo; hoàn tất khi ví dụ có thể đi vào và thoát ra mà không gặp AttributeError.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- postgresql, python
- Lĩnh vực
- databases
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100