Skip to content

Commit

Permalink
Use try except instead of getattr
Browse files Browse the repository at this point in the history
  • Loading branch information
fosterseth committed Nov 14, 2022
1 parent ad858b2 commit ea537d0
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions channels/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ async def __call__(self, scope, receive, send):
self.channel_receive = functools.partial(
self.channel_layer.receive, self.channel_name
)
if getattr(self.channel_layer, "clean_channel", None) and callable(self.channel_layer.clean_channel):
cancel_callback = functools.partial(self.channel_layer.clean_channel, self.channel_name)
else:
cancel_callback = None
# Handler to call when dispatch task is cancelled
cancel_callback = None
try:
if callable(self.channel_layer.clean_channel):
cancel_callback = functools.partial(self.channel_layer.clean_channel, self.channel_name)
except AttributeError:
pass
# Store send function
if self._sync:
self.base_send = async_to_sync(send)
Expand Down

0 comments on commit ea537d0

Please sign in to comment.