MagicStack / MagicStack/asyncpg

using notify listener with all-caps channel names

Abierto
#788 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Python
Estrellas
8.1k
Forks
468
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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!

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Busca add_listener y utils._quote_ident, y luego reproduce el comportamiento indicado con un canal de notificaciones de PostgreSQL escrito completamente en mayúsculas. Se considera terminado cuando los canales escritos completamente en mayúsculas pueden registrarse y recibir notificaciones, mientras el comportamiento existente del listener permanece intacto.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
postgresql, python
Área
databases
Tipo de issue
Error
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.