base.py: TypeError: 'str' object is not callable when importing a module fails
|Reported by:||miohtama||Owned by:||gptvnt|
|Cc:||tomi.kyostila@…, say4ne@…||Triage Stage:||Accepted|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
If you specify a module which does not import (it has syntax error or missing dependendies), base.py will raise mysterious TypeError. This is because urlresolver does not raise an exception when callback is not callable, but returns the original string instead.
This makes it very difficult for a developer to track down the real cause of the problem, since the orignal ImportError is silently eaten.
I suggest that urlresolver would raise an exception on invalid look-ups. I can create test case and patch if there is no reason why the current behavior should kept.
Steps to reproduce.
- Create a views.py module with any function
- Make views.py have an invalid import
import x def any_function(request, *args, **kwargs): pass
- Add views.py to urlconf, e.g.
- Use test client to get the URI
c = Client() response = c.get("/sampleurl/")
Sample result below:
Traceback (most recent call last): File "/home/moo/workspace/web/dependencies/django-go/scaler/tests/scaletest.py", line 102, in testServeScaledImage response = c.get(uri) File "/home/moo/workspace/web/dependencies/django-trunk/django/test/client.py", line 219, in get return self.request(**r) File "/home/moo/workspace/web/dependencies/django-trunk/django/core/handlers/base.py", line 82, in _real_get_response response = callback(request, *callback_args, **callback_kwargs) TypeError: 'str' object is not callable
Change History (9)
comment:1 Changed 8 years ago by jacob
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
comment:6 Changed 5 years ago by gptvnt
- Owner changed from nobody to gptvnt
- Status changed from new to assigned