Skip to content

Commit

Permalink
feat: re-enable safe quote
Browse files Browse the repository at this point in the history
  • Loading branch information
cofin committed Dec 30, 2024
1 parent 13a82e5 commit 1c3f9d8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions litestar/channels/backends/psycopg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
from .base import ChannelsBackend


def _safe_quote(ident: str) -> str:
return '"{}"'.format(ident.replace('"', '""')) # sourcery skip


class PsycoPgChannelsBackend(ChannelsBackend):
_listener_conn: AsyncConnection[Any]

Expand All @@ -32,13 +36,13 @@ async def publish(self, data: bytes, channels: Iterable[str]) -> None:

async def subscribe(self, channels: Iterable[str]) -> None:
for channel in set(channels) - self._subscribed_channels:
await self._listener_conn.execute(SQL("LISTEN {}").format(Identifier(channel)))
await self._listener_conn.execute(SQL("LISTEN {}").format(Identifier(_safe_quote(channel))))

self._subscribed_channels.add(channel)

async def unsubscribe(self, channels: Iterable[str]) -> None:
for channel in channels:
await self._listener_conn.execute(SQL("UNLISTEN {}").format(Identifier(channel)))
await self._listener_conn.execute(SQL("UNLISTEN {}").format(Identifier(_safe_quote(channel))))
self._subscribed_channels = self._subscribed_channels - set(channels)

async def stream_events(self) -> AsyncGenerator[tuple[str, bytes], None]:
Expand Down

0 comments on commit 1c3f9d8

Please sign in to comment.