django_longpolling icon indicating copy to clipboard operation
django_longpolling copied to clipboard

Timeout overridden to None in BaseLongPollingView dispatch method

Open theJenix opened this issue 11 years ago • 4 comments

Using Django 1.6.1, and django_longpolling 0.1.1 (installed using pip), it would appear that the timeout value passed to BaseLongPollingView (either through the as_view method or set via derived class) is ignored. It looks like the following line in dispatch is the culprit:

self.timeout = self.kwargs.get('channel')

In my case, kwargs is empty (from Django); if this is standard, then self.timeout should not be set here without checking to make sure there's a value in kwargs to set.

theJenix avatar Feb 09 '14 05:02 theJenix

I worked around this by overriding dispatch in my derived class:

def dispatch(self, request, *args, **kwargs):
    kwargs['channel'] = self.timeout
    return BaseLongPollingView.dispatch(self, request, *args, **kwargs)

This is functional, but sub-optimal. It would be better if BaseLongPollingVIew checked existence of the key in kwargs before accessing it.

theJenix avatar Feb 09 '14 05:02 theJenix

Hi, thanks for pointing this out. I forgot to cleanup kwargs['channel'] = self.timeout from a previous version, that line is actually doing nothing than confuse the reader.

You should override the timeout subclassing one of the two view class and overriding the timeout attribute (default is 30s)

tbarbugli avatar Feb 09 '14 10:02 tbarbugli

0.1.2 is available on pip

tbarbugli avatar Feb 09 '14 10:02 tbarbugli

:thumbsup:

theJenix avatar Feb 10 '14 14:02 theJenix