Skip to content

Bug: Typo in websocket_listener decorator argument passing #4406

@Peopl3s

Description

@Peopl3s

Description

In the websocket_listener decorator function, located in litestar/handlers/websocket_handlers/listener.py, there appears to be a typo when passing the guards parameter to the WebsocketListenerRouteHandler constructor.

The websocket_listener decorator's signature correctly defines a parameter named guards:

 guards: list[Guard] | None = None,

However, within the decorator function inside websocket_listener, when WebsocketListenerRouteHandler is instantiated, the guards parameter is passed as guard (singular):

 guard=guards,

The WebsocketListenerRouteHandler constructor (which inherits from WebsocketRouteHandler, which in turn inherits from BaseRouteHandler) expects a parameter named guards (plural). This mismatch will likely lead to a runtime error, such as a TypeError if WebsocketListenerRouteHandler doesn't have a guard parameter, or the guards configuration will simply be ignored if guard is implicitly caught by **kwargs and then not processed correctly.

Impact:

  • Any guards defined for a websocket_listener will not be correctly applied to the WebsocketListenerRouteHandler.
  • The application might raise a TypeError during startup or when attempting to register the websocket listener, depending on how argument parsing is handled in the WebsocketListenerRouteHandler constructor and its parent classes.

Solution:

Change guard=guards to guards=guards in the websocket_listener decorator function to correctly pass the guards parameter to the WebsocketListenerRouteHandler constructor.

URL to code causing the issue

No response

MCVE

Steps to reproduce

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Screenshots

No response

Logs


Litestar Version

2.18.0

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🐛This is something that is not working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions