hyde: TypeError: can't compare offset-naive and offset-aware datetimes

Hi,

I’m running into strange problems with the created: metadata. I started describing the problem here. I’m using the hyde.ext.plugins.git.GitDatesPlugin, Hyde 0.8.4, Python 2.7.2.

In my site.yaml, I have set created: git. If that’s the only place where I set the created metadata, everything works fine, with the datestamp coming from git. However, there’s cases where I want to manually set the created to some other timestamp. But as soon as I enter the line created: !!timestamp '2012-01-05 17:20:20 +01:00' into one of my source documents, the site generation fails:

Traceback (most recent call last):
  File "/home/andreas/.virtualenvs/hyde/bin/hyde", line 9, in <module>
    load_entry_point('hyde==0.8.4', 'console_scripts', 'hyde')()
  File "/home/andreas/.virtualenvs/hyde/lib/python2.7/site-packages/hyde/main.py", line 10, in main
    Engine().run()
  File "/home/andreas/.virtualenvs/hyde/lib/python2.7/site-packages/hyde/engine.py", line 39, in run
    super(Engine, self).run(args)
  File "/home/andreas/.virtualenvs/hyde/lib/python2.7/site-packages/commando.py", line 198, in run
    args.run(self, args)
  File "/home/andreas/.virtualenvs/hyde/lib/python2.7/site-packages/hyde/engine.py", line 118, in gen
    gen.generate_all(incremental=incremental)
  File "/home/andreas/.virtualenvs/hyde/lib/python2.7/site-packages/hyde/generator.py", line 202, in generate_all
    self.events.begin_site()
  File "/home/andreas/.virtualenvs/hyde/lib/python2.7/site-packages/hyde/plugin.py", line 44, in __call_plugins__
    res = function(*args)
  File "/home/andreas/.virtualenvs/hyde/lib/python2.7/site-packages/hyde/ext/plugins/sorter.py", line 128, in begin_site
    for prev, next in pairwalk(walker()):
  File "/home/andreas/.virtualenvs/hyde/lib/python2.7/site-packages/hyde/util.py", line 98, in method__
    return method_(*args, **kwargs)
  File "/home/andreas/.virtualenvs/hyde/lib/python2.7/site-packages/hyde/ext/plugins/sorter.py", line 69, in sort_method
    reverse=reverse)
TypeError: can't compare offset-naive and offset-aware datetimes

This also happens when I change the line to created: !!timestamp '2012-01-05 17:20:20'.

I’m at a loss here – what’s going wrong? Any help is greatly appreciated!

About this issue

  • Original URL
  • State: open
  • Created 12 years ago
  • Comments: 16 (10 by maintainers)

Most upvoted comments

I’m having the same issue, when trying to overwrite creation and modified dates in single posts. My site.yaml also uses my created: git and modified: git During site generation I get the error as stated above while processing sorter.py: TypeError: can’t compare offset-naive and offset-aware datetimes

A work around that worked for me, ist to remove the timezone from the parsed git timestamp by adding created = created.replace(tzinfo=None) Line 52 and modified = modified.replace(tzinfo=None) Line 55

However this is not a real fix because the timezone offset is lost. I would prefer a solution which parses !!timestamp ‘2012-11-07 15:08:00 +01:00’ correctly (including the tz offset).