#23403: Sitemap bug
-----------------------------------+--------------------------------------
Reporter: igorcc | Owner: igorcc
Type: Bug | Status: assigned
Component: contrib.sitemaps | Version: 1.7
Severity: Normal | Resolution:
Keywords: date utctimetuple | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by timgraham):
* needs_tests: 0 => 1
* easy: 1 => 0
Old description:
> When building a sitemap I receive
> jango Version: 1.7
> Exception Type: AttributeError
> Exception Value: 'datetime.date' object has no attribute
> 'utctimetuple'
>
> Exception Location: <skipped>/Django/lib/python2.7/site-
> packages/django/contrib/sitemaps/views.py in sitemap, line 78
>
> Workaround can be done as:
> diff --git a/django/contrib/sitemaps/views.py
> b/django/contrib/sitemaps/views.py
> index aa184e9..d74c55b 100644
> --- a/django/contrib/sitemaps/views.py
> +++ b/django/contrib/sitemaps/views.py
> @@ -8,6 +8,7 @@ from django.http import Http404
> from django.template.response import TemplateResponse
> from django.utils import six
> from django.utils.http import http_date
> +from datetime import datetime
>
> def x_robots_tag(func):
> @@ -71,7 +72,7 @@ def sitemap(request, sitemaps, section=None,
> raise Http404("No page '%s'" % page)
> response = TemplateResponse(request, template_name, {'urlset':
> urls},
> content_type=content_type)
> - if hasattr(site, 'latest_lastmod'):
> + if hasattr(site, 'latest_lastmod') and type(site.latest_lastmod) is
> datetime:
> # if latest_lastmod is defined for site, set header so as
> # ConditionalGetMiddleware is able to send 304 NOT MODIFIED
> response['Last-Modified'] = http_date(
New description:
When building a sitemap I receive
{{{
Django Version: 1.7
Exception Type: AttributeError
Exception Value: 'datetime.date' object has no attribute
'utctimetuple'
Exception Location: <skipped>/Django/lib/python2.7/site-
packages/django/contrib/sitemaps/views.py in sitemap, line 78
}}}
Workaround can be done as:
{{{
diff --git a/django/contrib/sitemaps/views.py
b/django/contrib/sitemaps/views.py
index aa184e9..d74c55b 100644
--- a/django/contrib/sitemaps/views.py
+++ b/django/contrib/sitemaps/views.py
@@ -8,6 +8,7 @@ from django.http import Http404
from django.template.response import TemplateResponse
from django.utils import six
from django.utils.http import http_date
+from datetime import datetime
def x_robots_tag(func):
@@ -71,7 +72,7 @@ def sitemap(request, sitemaps, section=None,
raise Http404("No page '%s'" % page)
response = TemplateResponse(request, template_name, {'urlset': urls},
content_type=content_type)
- if hasattr(site, 'latest_lastmod'):
+ if hasattr(site, 'latest_lastmod') and type(site.latest_lastmod) is
datetime:
# if latest_lastmod is defined for site, set header so as
# ConditionalGetMiddleware is able to send 304 NOT MODIFIED
response['Last-Modified'] = http_date(
}}}
--
Comment:
Could you please include code to reproduce the issue (ideally as a test
for Django's test suite)? Did your code work in Django 1.6?
--
Ticket URL: <https://code.djangoproject.com/ticket/23403#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.49beec6b422f73388cfc7d7582d9edf5%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.