MagicStack / MagicStack/asyncpg

using notify listener with all-caps channel names

Đang mở
#788 1 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ả

Hello,

I have a project where we set all our notify listeners up using all-caps channel names. In applying your package I found this didn't work, since the add_listener function sends the channel to postgres as a quoted identifier. I monkey patched as such to get it to work for my project:

async def add_listener(self, channel, callback, quote=True):
    """Add a listener for Postgres notifications.

    :param str channel: Channel to listen on.

    :param callable callback:
        A callable receiving the following arguments:
        **connection**: a Connection the callback is registered with;
        **pid**: PID of the Postgres server that sent the notification;
        **channel**: name of the channel the notification was sent to;
        **payload**: the payload.

    :param quote:
        specifies the channel name should should be sent as quoted identifier
    """
    self._check_open()
    if not quote:
        channel = channel.lower()
    if channel not in self._listeners:
        if quote:
            await self.fetch('LISTEN {}'.format(utils._quote_ident(channel)))
        else:
            await self.fetch('LISTEN {}'.format(channel))
        self._listeners[channel] = set()
    self._listeners[channel].add(callback)

Would you consider a pull request with this change? I would think I am not the only one who uses the listeners this way.

Thanks!

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

Tìm add_listener và utils._quote_ident, sau đó tái hiện hành vi được báo cáo với một kênh thông báo PostgreSQL hoàn toàn viết hoa. Hoàn thành nghĩa là các kênh hoàn toàn viết hoa có thể được đăng ký và nhận thông báo, trong khi hành vi listener hiện có vẫn được giữ nguyên.

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ó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
45/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.