Opened 14 years ago
Closed 12 years ago
#15753 closed Bug (fixed)
test_simple_sitemap fails after executing test_requestsite_sitemap when Sites app and FetchFromCacheMiddleware are installed.
Reported by: | lucho | Owned by: | nobody |
---|---|---|---|
Component: | contrib.sitemaps | Version: | dev |
Severity: | Normal | Keywords: | test |
Cc: | krzysiumed@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
test_simple_sitemap fails after executing test_requestsite_sitemap when Sites app and FetchFromCacheMiddleware are installed.
The error:
====================================================================== FAIL: test_simple_sitemap (django.contrib.sitemaps.tests.basic.SitemapTests) A simple sitemap can be rendered ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/contrib/sitemaps/tests/basic.py", line 70, in test_simple_sitemap """ % (self.base_url, date.today().strftime('%Y-%m-%d'))) AssertionError: '<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n<url><loc>http://testserver/location/</loc><lastmod>2011-04-04</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>\n</urlset>\n' != '<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n<url><loc>http://example.com/location/</loc><lastmod>2011-04-04</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>\n</urlset>\n'
The way to reproduce it:
- Use Sites app in your project
- Use FetchFromCacheMiddleware middleware in your project
- Run the sitemaps.SitemapTests suite
The code that triggers the problem is this http://code.djangoproject.com/browser/django/trunk/django/contrib/sitemaps/tests/basic.py#L144
# Which does that - setting the Site app as not installed and requesting the url Site._meta.installed = False response = self.client.get('/simple/sitemap.xml')
If I execute the test case separate (./manage.py test sitemaps.SitemapTests.test_simple_sitemap) no error is observed, but executing the whole test suite leads to error in test_simple_sitemap which is executed right after the test_requestsite_sitemap.
If I comment out the test_requestsite_sitemap, no problem is observed.
If I don't use (comment out) FetchFromCacheMiddleware, no problem is observed.
This makes me think that it is some problem related to caching.
Attachments (1)
Change History (10)
comment:1 by , 14 years ago
comment:2 by , 14 years ago
I added a patch that worked for me fix_15753.diff.
It simply clears the cache in setUp.
comment:3 by , 14 years ago
Easy pickings: | unset |
---|---|
Has patch: | set |
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Accepted |
Looks like the fix works, but I need to know *why* it works before I can feel comfortable closing this one out.
comment:4 by , 13 years ago
UI/UX: | unset |
---|
I cannot reproduce this bug. The problem doesn't appear with the latest version. I checked revision 15906 tagged as 1.3 version, but the problem didn't appear too. I suggest to close this ticket.
comment:5 by , 13 years ago
Cc: | added |
---|
comment:6 by , 13 years ago
It is still reproducible. You must ensure to have all the necessary cache machinery enabled in your project. https://docs.djangoproject.com/en/1.3/topics/cache/
comment:7 by , 13 years ago
Keywords: | test added |
---|---|
Version: | 1.3 → SVN |
The problem is that in those tests, there are several requests for the same URL ('/simple/sitemap.xml', '/simple/sitemap-simple.xml'), so that's totally previsible that when caching is enabled, some already rendered contents are reused. The patch from lucho is one way to solve this. Another one would be to empty the cache just for the failing tests. A third approach would be to isolate the tests from unwanted middlewares (override_settings(MIDDLEWARE_CLASSES = ...).
comment:8 by , 13 years ago
Patch needs improvement: | unset |
---|
The response is cached indeed. I think cleaning cache in setUp is the easiest solution.
How cache is used during running tests? During executing django.contrib.sitemaps.tests.http.HTTPSitemapTest.test_requestsite_sitemap
the LocMemCache
instance is used:
- its method
get
is called with argumentkey='views.decorators.cache.cache_header..8e8e090224d76db794280be1b767ecc0.en-us'
; it returnsNone
; - next its method
set
is called with argumentskey='views.decorators.cache.cache_header..8e8e090224d76db794280be1b767ecc0.en-us'
andvalue=[]
; - next its method
set
is called one more time with arguments key='views.decorators.cache.cache_page..GET.8e8e090224d76db794280be1b767ecc0.d41d8cd98f00b204e9800998ecf8427e.en-us'and
value=<django.template.response.TemplateResponse object at 0x2894a10>`; after rendering the TemplateResponse instance its content is<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url><loc>http://testserver/location/</loc><lastmod>2012-02-05</lastmod><changefreq>never</changefreq><priority>0.5</priority></url> </urlset>
Then the django.contrib.sitemaps.tests.http.HTTPSitemapTest.test_simple_sitemap
is run:
- method
get
is called with argumentkey='views.decorators.cache.cache_header..8e8e090224d76db794280be1b767ecc0.en-us'
; it returns[]
; - method
get
is called one more time with argumentkey='views.decorators.cache.cache_page..GET.8e8e090224d76db794280be1b767ecc0.d41d8cd98f00b204e9800998ecf8427e.en-us'
; it returns<django.template.response.TemplateResponse object at 0x28d9a10>
- the cached TemplateResponse instance.
comment:9 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Sites = django.contrib.sites