Skip to content

Commit ea537d0

Browse files
committed
Use try except instead of getattr
1 parent ad858b2 commit ea537d0

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

channels/consumer.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ async def __call__(self, scope, receive, send):
4747
self.channel_receive = functools.partial(
4848
self.channel_layer.receive, self.channel_name
4949
)
50-
if getattr(self.channel_layer, "clean_channel", None) and callable(self.channel_layer.clean_channel):
51-
cancel_callback = functools.partial(self.channel_layer.clean_channel, self.channel_name)
52-
else:
53-
cancel_callback = None
50+
# Handler to call when dispatch task is cancelled
51+
cancel_callback = None
52+
try:
53+
if callable(self.channel_layer.clean_channel):
54+
cancel_callback = functools.partial(self.channel_layer.clean_channel, self.channel_name)
55+
except AttributeError:
56+
pass
5457
# Store send function
5558
if self._sync:
5659
self.base_send = async_to_sync(send)

0 commit comments

Comments
 (0)