MagicStack / MagicStack/asyncpg
using notify listener with all-caps channel names
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 8.1k
- Fork
- 468
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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!
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Cerca add_listener e utils._quote_ident, quindi riproduci il comportamento segnalato con un canale di notifiche PostgreSQL interamente in maiuscolo. Il lavoro è completato quando i canali interamente in maiuscolo possono essere registrati e ricevere notifiche, mantenendo intatto il comportamento esistente del listener.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- postgresql, python
- Ambito
- databases
- Tipo di issue
- Bug
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 45/100