4

I made an Atom feed in Django using a class that looks something like this:

class AtomFeed(Feed):

    feed_type = feedgenerator.Atom1Feed

    # ...

    def item_pubdate(self, post):
        return datetime.datetime(post.date.year, post.date.month, post.date.day)

The resulting XML for an item:

<entry>
  <title>..</title>
  <link href="..." rel="alternate"></link>
  <updated>2010-10-18T00:00:00+02:00</updated>
  <author><name>...</name></author>
  <id>...</id>
  <summary type="html">...</summary>
</entry>

The thing to note here is that the date goes in the atom:updated element, not the atom:published element.

The RFC clearly suggests to me that this is not the intended usage:

The "atom:updated" element is a Date construct indicating the most recent instant in time when an entry or feed was modified in a way the publisher considers significant. Therefore, not all modifications necessarily result in a changed atom:updated value.

Whereas:

The "atom:published" element is a Date construct indicating an instant in time associated with an event early in the life cycle of the entry.

This is more than just a theoretical problem. Google Reader, for example, does not seem to use the updated element, and uses the date that it first saw the item appear. As a result, it does not order the items properly upon first import of the feed.

The code in Django responsible for this:

django/utils/feedgenerator.py:331

if item['pubdate'] is not None:
    handler.addQuickElement(u"updated", rfc3339_date(item['pubdate']).decode('utf-8'))

There appears to be no mention of the published element.

Is this a bug in Django? Am I misunderstanding the Atom RFC? Am I missing something else?

Community
  • 1
  • 1
Thomas
  • 174,939
  • 50
  • 355
  • 478
  • I would say this is a definite bug in django. When I say "when I published it", I don't want my translator saying "last time I changed it". I see you've already [reported it](http://code.djangoproject.com/ticket/14656), so I guess time will tell. – eternicode Nov 11 '10 at 03:01
  • It doesn't seem like a "missing" feature. in Django 1.2 and 1.3 you can add attributes to the feed. If I remember well in 1.3 it is just necessary to add trough the method item_extra_kwargs of the Feed class. "return {'published': self.get_object().created }", this would work also to create podcast feeds and others kind of feeds with special items or attributes – Mario César Feb 14 '11 at 22:53
  • That's good news, but it doesn't address the fact that the `atom:updated` element is abused, and that the important `atom:published` element isn't used out-of-the-box at all. – Thomas Feb 15 '11 at 11:18

1 Answers1

1

You are not missing anything. The Atom RFC is correct, and this is a known bug in Django; see this Django bug.

It looks like a relatively simple fix, so feel free to get in there and patch it! ^_^

pythonian4000
  • 103
  • 1
  • 5
  • Hmm... now that I have read the comments to your question, what's the betting that you are the one that filed the bug? ~_~ – pythonian4000 Feb 18 '11 at 07:38
  • Yep, that was me ;) It has changed status to "accepted" though, so it has at least some degree of validity. – Thomas Feb 18 '11 at 07:58
  • 1
    Well, this is what first Stack Overflow answers are for - learning to read the entire question first! =) – pythonian4000 Feb 18 '11 at 10:53