MagicStack / MagicStack/asyncpg

Support a Pool `before_connect` callback to be used before a connection is created

Đang mở
#1,118 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

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.27.0
* **PostgreSQL version**: 14
* **Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?**: Local
* **Python version**: 3.9.9
* **Platform**: macos
* **Do you use pgbouncer?**: no
* **Did you install asyncpg with pip?**: yes
* **If you built asyncpg locally, which version of Cython did you use?**:
* **Can the issue be reproduced under both asyncio and
[uvloop](https://github.com/magicstack/uvloop)?**:

Hello! This is more of a feature request but I was wondering if there could be support for having a `before_connect` or similar callback when creating a Pool object that would run before a new connection is created? I see there is already an [init](https://github.com/MagicStack/asyncpg/blob/c2c8d20ba8c0057b0e0bc08bd892abc36862e553/asyncpg/pool.py#L1088-L1094) param which is run after a connection is made.

Our use case is that we use dynamic credentials to access our postgres database and want to make sure that when we create a connection we are using credentials that are not stale. Is this something that makes sense for this project? There is similar functionality in other libraries such as [sqlalchemy](https://docs.sqlalchemy.org/en/20/core/events.html#sqlalchemy.events.DialectEvents.do_connect) or [pgx](https://github.com/jackc/pgx/blob/5c63f646f820ca9696fc3515c1caf2a557d562e5/pgxpool/pool.go#L107-L109).

I was looking at how to do this as-is and there were two currently that I was exploring. One way would be to create our own Pool class which seems like a lot of maintainance for what we'd like to do. The other looked at creating a subclass and overriding the `acquire` and using `set_connect_args` but that would run every time we get a connection from a pool which would be wasteful as opposed to just when the creation happens.

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với asyncpg/pool.py, đặc biệt là callback init hiện có và các đường đi acquire/set_connect_args được mô tả trong issue, để hiểu khi nào các kết nối được tạo và khi nào chúng được lấy ra khỏi pool. Hoàn thành có nghĩa là một hook before-connect có thể làm mới thông tin xác thực động chỉ khi một kết nối pool mới được tạo, thay vì ở mỗi lần acquire.

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
database
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 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

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.