MagicStack / MagicStack/asyncpg

using notify listener with all-caps channel names

Open
#788 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
8.1k
Forks
468
PR merge metrics
No merged PRs in 30d

Description

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!

Contributor guide

No contributing guide indexed for this repository

Research direction

Search for add_listener and utils._quote_ident, then reproduce the reported behavior with an all-caps PostgreSQL notification channel. Done means all-caps channels can be registered and receive notifications while existing listener behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.