Compatibility with older versions of Python

Issue #7 open
Charles McLaughlin created an issue

Looks like the latest version of dogslow doesn't work with older versions of Python. I chatted with Erik about this -- maybe this is caused by a django url pattern not having a name.

Here's the stacktrace:

File "/Library/Python/2.6/site-packages/django/core/handlers/base.py" in get_response
  80.                     response = middleware_method(request)
File "/Library/Python/2.6/site-packages/dogslow/__init__.py" in process_request
  174.         if not self._is_exempt(request):
File "/Library/Python/2.6/site-packages/dogslow/__init__.py" in _is_exempt
  170.         return match and (match.url_name in

Exception Type: AttributeError at /
Exception Value: 'tuple' object has no attribute 'url_name'

Comments (7)

  1. thezilch

    This issue is an issue with Django compatibility and not Python. See https://code.djangoproject.com/ticket/13922 for the change of django.core.urlresolvers.resolve no longer returning a tuple, which was released with Django 1.2. Prior to 1.2, it doesn't appear simple to get the url_name.

    Similarly, custom loggers will break in similar fashion, which also attempt to resolve a url_name when passing a warning to the logger.

    91,100d90
    <     @staticmethod
    <     def _get_url_name(request):
    <         match = resolve(request.META.get('PATH_INFO'))
    <         # FIXME: Django pre-1.2 returns a tuple with no url_name attribute;
    <         # view_func (callback) is the first value passed in said tuple; let's
    <         # backport Django 1.2+ url_name construction.
    <         url_name = match and getattr(match, "url_name",
    <             ".".join((match[0].__module__, match[0].__name__)))
    <         return url_name
    < 
    167c157
    <                             WatchdogMiddleware._get_url_name(request),
    ---
    >                             resolve(request.META.get('PATH_INFO')).url_name,
    172a163
    > 
    177,178c168,169
    <         url_name = WatchdogMiddleware._get_url_name(request)
    <         return url_name and (url_name in
    ---
    >         match = resolve(request.META.get('PATH_INFO'))
    >         return match and (match.url_name in
    
  2. Former user Account Deleted

    I am experiencing exactly the same problem on Django Version 1.2.1 so not sure if Ticket #13922 was provided there. Please advice of a workaround without upgrading Django versions.

  3. Erik van Zijst repo owner

    It would appear that the snippet provided by @thezilch would work around the problem.

    It'd be awesome if you could give that a go and report back. I'm happy to pull it in.

  4. Charles McLaughlin reporter

    I was just curious what versions of Django were supported and stumbled upon this old issue. Too bad I didn't list the version I was trying to use here. But I'm pretty sure Dogslow works with Django 1.4, so perhaps close this issue since anything older than that isn't even supported by the Django project.

  5. Thomas Smith

    For the next release, I'm targeting the currently-supported Django versions, which are 1.8, 1.10, and 1.11. It will probably also work with older versions.

    Django 1.10 introduced a new middleware interface and deprecated the MIDDLEWARE_CLASSES interface that we use, so at some point we should at least introduce an adaptor to the new system.

  6. Log in to comment