MagicStack / MagicStack/asyncpg

using notify listener with all-caps channel names

Ouverte
#788 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
Python
Étoiles
8.1k
Forks
468
Métriques de merge des PR
Aucune PR mergée en 30 j

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!

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Recherchez add_listener et utils._quote_ident, puis reproduisez le comportement signalé avec un canal de notifications PostgreSQL entièrement en majuscules. C’est terminé lorsque les canaux entièrement en majuscules peuvent être enregistrés et recevoir des notifications, tout en préservant le comportement existant du listener.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
postgresql, python
Domaine
databases
Type d'issue
Bug
Difficulté
2/5
Temps estimé
1-3 heures
Activité
À l'abandon
Clarté
Clairement spécifiée
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.