I'm working on a patch for django-localeurl and I've bumped into a problem that puzzles me. To test the functionality added by my patch, I've added tests that triggers this error when I run them against Django trunk (no problem with older releases):
Traceback (most recent call last):
File "/home/al/dev/projects/django-localeurl/localeurl/tests/tests.py", line 498, in test_change_locale_check_session_disabled
self.client.post('/change/', data={'locale': 'de', 'next': '/foo'})
File "/home/al/dev/projects/django-localeurl/.tox/py26-trunk/lib/python2.6/site-packages/django/test/client.py", line 449, in post
response = super(Client, self).post(path, data=data, content_type=content_type, **extra)
File "/home/al/dev/projects/django-localeurl/.tox/py26-trunk/lib/python2.6/site-packages/django/test/client.py", line 262, in post
return self.request(**r)
File "/home/al/dev/projects/django-localeurl/.tox/py26-trunk/lib/python2.6/site-packages/django/test/client.py", line 381, in request
response = self.handler(environ)
File "/home/al/dev/projects/django-localeurl/.tox/py26-trunk/lib/python2.6/site-packages/django/test/client.py", line 84, in __call__
response = self.get_response(request)
File "/home/al/dev/projects/django-localeurl/.tox/py26-trunk/lib/python2.6/site-packages/django/core/handlers/base.py", line 179, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/home/al/dev/projects/django-localeurl/.tox/py26-trunk/lib/python2.6/site-packages/django/core/handlers/base.py", line 224, in handle_uncaught_exception
if resolver.urlconf_module is None:
File "/home/al/dev/projects/django-localeurl/.tox/py26-trunk/lib/python2.6/site-packages/django/core/urlresolvers.py", line 323, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/home/al/dev/projects/django-localeurl/.tox/py26-trunk/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/al/dev/projects/django-localeurl/localeurl/urls.py", line 5, in <module>
url(r'^change/', change_locale, name='localeurl_change_locale'),
File "/home/al/dev/projects/django-localeurl/.tox/py26-trunk/lib/python2.6/site-packages/django/conf/urls/__init__.py", line 60, in url
return RegexURLPattern(regex, view, kwargs, name)
File "/home/al/dev/projects/django-localeurl/.tox/py26-trunk/lib/python2.6/site-packages/django/core/urlresolvers.py", line 172, in __init__
LocaleRegexProvider.__init__(self, regex)
TypeError: unbound method __init__() must be called with LocaleRegexProvider instance as first argument (got RegexURLPattern instance instead)
But When I read the code that triggers this exception, I can't see how this can happen. In order to understand the situation I added those print statements above the line where the base __init__
is called:
print
print "self.__class__:", self.__class__
print "self.__class__.__bases__:", self.__class__.__bases__
print "isinstance(self, LocaleRegexProvider):", isinstance(self, LocaleRegexProvider)
print
LocaleRegexProvider.__init__(self, regex)
In some cases this gives me the expected output:
self.__class__: <class 'django.core.urlresolvers.RegexURLPattern'>
self.__class__.__bases__: (<class 'django.core.urlresolvers.LocaleRegexProvider'>,)
isinstance(self, LocaleRegexProvider): True
But in some cases it gives me this strange result:
self.__class__: <class 'django.core.urlresolvers.RegexURLPattern'>
self.__class__.__bases__: (<class 'django.core.urlresolvers.LocaleRegexProvider'>,)
isinstance(self, LocaleRegexProvider): False
Initially I thought some other part of Django might be dynamically changing the base class of the RegexURLPattern
instance (here referred as self
), which causes an exception to be raised when calling LocaleRegexProvider.__init__
. My supposition seems to be confirmed by the result of isinstance
but printing out the __bases__
contradict this. I thought that if LocaleRegexProvider
is in the list of base classes, isinstance
should always return True
. What am I missing here?