Opened 17 years ago
Closed 17 years ago
#5920 closed (invalid)
Error AttributeError: 'function' object has no attribute 'status_code' in 6668 version
Reported by: | aaloy | Owned by: | Ramiro Morales |
---|---|---|---|
Component: | Core (Cache system) | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
This error appears in the last trunk, it not appears in 6473 version and I don't get it in all pages.
Traceback (most recent call last): File "/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 278, in run self.result = application(self.environ, self.start_response) File "/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 620, in __call__ return self.application(environ, start_response) File "/usr/lib/python2.5/site-packages/django/core/handlers/wsgi.py", line 209, in __call__ response = middleware_method(request, response) File "/usr/lib/python2.5/site-packages/django/middleware/gzip.py", line 14, in process_response if response.status_code != 200 or len(response.content) < 200:
Change History (9)
comment:1 by , 17 years ago
comment:2 by , 17 years ago
Hmm, the cache_page decorator is working for me in trunk (r6826) - are there more details to reproduce? What middleware do you have installed in what order, what's an example of a view that does work correctly, etc?
comment:3 by , 17 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
No feedback since several months. Closing it, since some people said 'worksforme'.
Please reopen if problem still happens with current SVN trunk.
comment:4 by , 17 years ago
Component: | Uncategorized → Cache system |
---|---|
Resolution: | invalid |
Status: | closed → reopened |
This still doesn't seem to work in the svn trunk. I get the following error:
Traceback (most recent call last):
File "G:\Python25\lib\site-packages\django\core\servers\basehttp.py", line 277, in run
self.result = application(self.environ, self.start_response)
File "G:\Python25\lib\site-packages\django\core\servers\basehttp.py", line 631, in call
return self.application(environ, start_response)
File "G:\Python25\lib\site-packages\django\core\handlers\wsgi.py", line 209, in call
response = middleware_method(request, response)
File "G:\Python25\lib\site-packages\django\middleware\common.py", line 90, in process_response
if response.status_code == 404:
AttributeError: 'function' object has no attribute 'status_code'
I use cache_page in urls.py. Using @cache_page in views seems to work though (or at least no errors were generated).
I have the following middleware set:
MIDDLEWARE_CLASSES = (
'django.middleware.cache.CacheMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
)
I couldn't determine if CacheMiddleware was needed for individual views or not so I've tested with and without it, with the same result.
comment:5 by , 17 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:6 by , 17 years ago
Owner: | changed from | to
---|---|
Status: | reopened → new |
comment:7 by , 17 years ago
Status: | new → assigned |
---|
@MihaiD: I have been able to reproduce the problem by using cache_page
in the URLconf as you describe but by using the string syntax for the view being "decorated" instead of the callable syntax (see http://www.djangoproject.com/documentation/release_notes_0.96/#urlconf-improvements). This confuses django.utils.decorators.decorator_from_middleware()
than then ends pushing a stub function as a decorator/middleware method parameter in a place where a HttpResponse is expected.
import views urlpatterns = patterns('', (r'^foo/$', cache_page('myproj.myapp.views.myview')), # This is WRONG (r'^foo/$', cache_page(views.myview)), # This is OK )
Can you confirm this is what you are doing in your setup?. If so, I will then change Component field of this ticket to Documentation and will submit a patch against the URL dispatcher docs to clarify this.
comment:8 by , 17 years ago
Yep, that's what I was trying to do. Work's fine with the second syntax you wrote
comment:9 by , 17 years ago
Resolution: | → invalid |
---|---|
Status: | assigned → closed |
The OP didn't provide enough information so we can't say for sure if the problem is the same one that got diagnosed (other possible causes could have been some bugs the decorator from middleware stuff had that were polished as time passed), but a a second reporter with the same symptoms did. He was using a decorator in a wrong way. Closing this ticket and opening #6832 to clarify the usage case description in the documentation.
It seems the issue is not with http but with the cache_page decorator. The decorator worked with the previos version and does not work with the trunk versions.
This worke on version 6473