[Django] #23403: Sitemap bug

12 views
Skip to first unread message

Django

unread,
Sep 3, 2014, 4:46:34 AM9/3/14
to django-...@googlegroups.com
#23403: Sitemap bug
----------------------------------+-------------------------------
Reporter: igorcc | Owner: nobody
Type: Bug | Status: new
Component: contrib.sitemaps | Version: 1.7
Severity: Normal | Keywords: date utctimetuple
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 1 | UI/UX: 0
----------------------------------+-------------------------------
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(

--
Ticket URL: <https://code.djangoproject.com/ticket/23403>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 3, 2014, 4:47:09 AM9/3/14
to django-...@googlegroups.com
#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: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by igorcc):

* owner: nobody => igorcc
* needs_better_patch: => 0
* status: new => assigned
* needs_tests: => 0
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/23403#comment:1>

Django

unread,
Sep 3, 2014, 7:41:52 AM9/3/14
to django-...@googlegroups.com
#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:

New description:

When building a sitemap I receive

{{{
Django Version: 1.7

--

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

unread,
Sep 4, 2014, 1:36:45 AM9/4/14
to django-...@googlegroups.com
#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
-----------------------------------+--------------------------------------

Comment (by igorcc):

This code works fine in Django 1.6.6
The error appeared in Django 1.7
I suppose this error is highly dependent on the type of date_field - see
info_dict1 in urls.py

Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/23403#comment:3>

Django

unread,
Sep 4, 2014, 8:49:26 AM9/4/14
to django-...@googlegroups.com
#23403: sitemap crashes if lastmod returns a date (instead of datetime)
-----------------------------------+------------------------------------

Reporter: igorcc | Owner: igorcc
Type: Bug | Status: assigned
Component: contrib.sitemaps | Version: 1.7
Severity: Release blocker | Resolution:
Keywords: date utctimetuple | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1
* stage: Unreviewed => Accepted
* severity: Normal => Release blocker


Comment:

I think the correct solution would be to use the date for the `Last-
Modified` header, not skip it as the patch in the ticket description does.

Here's the commit where the feature was added:
https://github.com/django/django/commit/8f5533ab250df07ea84f98d39808806e282468a5

--
Ticket URL: <https://code.djangoproject.com/ticket/23403#comment:4>

Django

unread,
Sep 4, 2014, 10:25:03 AM9/4/14
to django-...@googlegroups.com
#23403: sitemap crashes if lastmod returns a date (instead of datetime)
-----------------------------------+------------------------------------
Reporter: igorcc | Owner: igorcc
Type: Bug | Status: assigned
Component: contrib.sitemaps | Version: 1.7

Severity: Release blocker | Resolution:
Keywords: date utctimetuple | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by igorcc):

OK, in this case there could be more clear solution, working for both date
and datetime:

@@ -75,5 +75,5 @@


# if latest_lastmod is defined for site, set header so as
# ConditionalGetMiddleware is able to send 304 NOT MODIFIED
response['Last-Modified'] = http_date(

- timegm(site.latest_lastmod.utctimetuple()))
+ timegm(site.latest_lastmod.timetuple()))
return response

Thank you!

--
Ticket URL: <https://code.djangoproject.com/ticket/23403#comment:5>

Django

unread,
Sep 5, 2014, 1:17:47 PM9/5/14
to django-...@googlegroups.com
#23403: sitemap crashes if lastmod returns a date (instead of datetime)
-----------------------------------+------------------------------------
Reporter: igorcc | Owner: igorcc
Type: Bug | Status: assigned
Component: contrib.sitemaps | Version: 1.7

Severity: Release blocker | Resolution:
Keywords: date utctimetuple | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by timgraham):

Does that change alter the value that's returned if the datetime is time-
zone aware? Do you plan to add a regression test for this?

--
Ticket URL: <https://code.djangoproject.com/ticket/23403#comment:6>

Django

unread,
Sep 9, 2014, 12:45:10 PM9/9/14
to django-...@googlegroups.com
#23403: sitemap crashes if lastmod returns a date (instead of datetime)
-----------------------------------+-------------------------------------
Reporter: igorcc | Owner: timgraham
Type: Bug | Status: assigned
Component: contrib.sitemaps | Version: 1.7

Severity: Release blocker | Resolution:
Keywords: date utctimetuple | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-----------------------------------+-------------------------------------
Changes (by timgraham):

* owner: igorcc => timgraham


--
Ticket URL: <https://code.djangoproject.com/ticket/23403#comment:7>

Django

unread,
Sep 9, 2014, 1:37:14 PM9/9/14
to django-...@googlegroups.com
#23403: sitemap crashes if lastmod returns a date (instead of datetime)
-----------------------------------+-------------------------------------
Reporter: igorcc | Owner: timgraham
Type: Bug | Status: assigned
Component: contrib.sitemaps | Version: 1.7

Severity: Release blocker | Resolution:
Keywords: date utctimetuple | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 1 => 0
* needs_tests: 1 => 0


Comment:

[https://github.com/django/django/pull/3206 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/23403#comment:8>

Django

unread,
Sep 11, 2014, 3:56:51 PM9/11/14
to django-...@googlegroups.com
#23403: sitemap crashes if lastmod returns a date (instead of datetime)
-------------------------------------+-------------------------------------

Reporter: igorcc | Owner: timgraham
Type: Bug | Status: assigned
Component: contrib.sitemaps | Version: 1.7
Severity: Release blocker | Resolution:
Keywords: date utctimetuple | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by prestontimmons):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/23403#comment:9>

Django

unread,
Sep 11, 2014, 4:10:41 PM9/11/14
to django-...@googlegroups.com
#23403: sitemap crashes if lastmod returns a date (instead of datetime)
-------------------------------------+-------------------------------------
Reporter: igorcc | Owner: timgraham
Type: Bug | Status: closed
Component: contrib.sitemaps | Version: 1.7
Severity: Release blocker | Resolution: fixed

Keywords: date utctimetuple | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"66580fe97c0ec8fe16ce7ff7f75a67c7f2340f83"]:
{{{
#!CommitTicketReference repository=""
revision="66580fe97c0ec8fe16ce7ff7f75a67c7f2340f83"
Fixed #23403 -- Fixed crash in contrib.sitemaps if lastmod returned a date
rather than datetime.

Thanks igorcc for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23403#comment:10>

Django

unread,
Sep 11, 2014, 4:15:57 PM9/11/14
to django-...@googlegroups.com
#23403: sitemap crashes if lastmod returns a date (instead of datetime)
-------------------------------------+-------------------------------------
Reporter: igorcc | Owner: timgraham
Type: Bug | Status: closed
Component: contrib.sitemaps | Version: 1.7

Severity: Release blocker | Resolution: fixed
Keywords: date utctimetuple | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"7de55fa68e694b84e5ea9c383d87153b5be0d43a"]:
{{{
#!CommitTicketReference repository=""
revision="7de55fa68e694b84e5ea9c383d87153b5be0d43a"
[1.7.x] Fixed #23403 -- Fixed crash in contrib.sitemaps if lastmod


returned a date rather than datetime.

Thanks igorcc for the report and Preston Timmons for review.

Backport of 66580fe97c from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23403#comment:11>

Reply all
Reply to author
Forward
0 new messages