getpelican / pelican

Static site generator that supports Markdown and reST syntax. Powered by Python.
https://getpelican.com
GNU Affero General Public License v3.0
12.55k stars 1.81k forks source link

WITH_FUTURE_DATES = False crashes comparing datetimes #1666

Closed zackw closed 9 years ago

zackw commented 9 years ago

I tried to set WITH_FUTURE_DATES = False for a site where I want to write posts in advance and have them automatically appear (via a cron job) when their date comes around. This mode appears to have been broken for quite some time: I get this error message for every single post:

ERROR: Could not process [REDACTED]
  | can't compare offset-naive and offset-aware datetimes
  |___
  | Traceback (most recent call last):
  |   File ".../site-packages/pelican/generators.py", line 502, in generate_context
  |     context_sender=self)
  |   File ".../site-packages/pelican/readers.py", line 492, in read_file
  |     context=context)
  |   File ".../site-packages/pelican/contents.py", line 136, in __init__
  |     if hasattr(self, 'date') and self.date > SafeDatetime.now():
  | TypeError: can't compare offset-naive and offset-aware datetimes

and the generated site is empty.

This is with Python 2.7, fwiw.

ingwinlu commented 9 years ago

https://github.com/getpelican/pelican/issues/1536

zackw commented 9 years ago

Hm, so, fixed in the development version? I'll test that.

eflee commented 9 years ago

Where is this?

It's broken with WITH_FUTURE_DATES = True with Pelican installed via pip install -e "git+https://github.com/getpelican/pelican.git#egg=pelican"

avaris commented 9 years ago

@eflee broken how?

russellballestrini commented 9 years ago

This is still an issue for me in pelican 3.5.0. This issue doesn't occur in pelican 3.4.0. Here is some proof:

pelican --version
3.5.0

Same error whether WITH_FUTURE_DATES is True or False:

(env)myuser@myhost ~/h/myblog> make html;
find /home/myuser/hg/myblog/output -mindepth 1 -delete
pelican /home/myuser/hg/myblog/content -o /home/myuser/hg/myblog/output -s /home/myuser/hg/myblog/pelicanconf.py 
CRITICAL: can't subtract offset-naive and offset-aware datetimes
Makefile:46: recipe for target '/home/myuser/hg/myblog/output/index.html' failed
make: *** [/home/myuser/hg/myblog/output/index.html] Error 1
pelican --version
3.4.0
(env)myuser@myhost ~/h/myblog> make html;
find /home/myuser/hg/myblog/output -mindepth 1 -delete
pelican /home/myuser/hg/myblog/content -o /home/myuser/hg/myblog/output -s /home/myuser/hg/myblog/pelicanconf.py
Done: Processed 32 article(s), 0 draft(s) and 0 page(s) in 0.48 seconds.
Done
justinmayer commented 9 years ago

@russellballestrini: Perhaps you should try the current master branch?

russellballestrini commented 9 years ago

@justinmayer ok, will test.

russellballestrini commented 9 years ago

Please ignore my comments above, not directly related to this error

install latest master from github:

pip install -e "git+https://github.com/getpelican/pelican.git#egg=pelican"

check version:

pelican --version
3.5.0
CRITICAL: can't subtract offset-naive and offset-aware datetimes

On further investigation I deduced that it is my custom theme that is attempting to use the date object that is causing the exception!

At some point Pelican started using timezone aware datetime objects and my code was trying to perform math on them without timezones. The quick hack work around to fix my theme was to strip the timezone data from the datetime object, like so _(articledate.html):

<span title="{{ article.date.isoformat() }}" class="published">
  {{ article.date.replace(tzinfo=None) | ago(1,'Posted {} ago') }}
</span>
justinmayer commented 9 years ago

This should be addressed in 3.6, which was just released.

mlissner commented 9 years ago

Ran into this error with pelican 3.6.0 and Python 3.4.

Fixed it by updating my pelicans-plugins repo with:

git pull --recurse-submodules
git submodule update --recursive