MagicStack / MagicStack/asyncpg

using notify listener with all-caps channel names

未关闭
#788 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
8.1k
派生
468
PR 合并指标
30 天内没有已合并 PR

描述

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!

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

搜索 add_listener 和 utils._quote_ident,然后使用全大写的 PostgreSQL 通知通道复现所报告的行为。完成的标准是全大写通道可以注册并接收通知,同时现有的 listener 行为保持不变。

由索引模型根据 Issue 内容生成。

评估

技术栈
postgresql, python
领域
databases
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。