MagicStack / MagicStack/asyncpg

using notify listener with all-caps channel names

Offen
#788 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
8.1k
Forks
468
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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!

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Suche nach add_listener und utils._quote_ident und reproduziere anschließend das gemeldete Verhalten mit einem vollständig großgeschriebenen PostgreSQL-Benachrichtigungskanal. Erledigt bedeutet, dass vollständig großgeschriebene Kanäle registriert werden und Benachrichtigungen empfangen können, während das bestehende Listener-Verhalten intakt bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
postgresql, python
Bereich
databases
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.