TypeError: can't compare offset-naive and offset-aware datetimes
See original GitHub issueHi,
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!
Issue Analytics
- State:
- Created 12 years ago
- Comments:16 (10 by maintainers)
Top Results From Across the Web
Can't compare naive and aware datetime.now() <= challenge ...
So the way I would solve this problem is to make sure the two datetimes are in the right timezone.
Read more >Comparing Datetimes in Python with and without Timezones
In this tutorial, we'll go over how to compare dates in Python, ... TypeError: can't compare offset-naive and offset-aware datetimes.
Read more >can't compare offset-naive and offset-aware datetimes - Reddit
I asked a question similar to this before but I didn't understand the answers given. What timezone were the bare timestamps taken in?...
Read more >PYTHON : django 1.4 - can't compare offset-naive ... - YouTube
PYTHON : django 1.4 - can't compare offset - naive and offset - aware datetimes [ Gift : Animated Search Engine ...
Read more >can't compare offset-naive and offset-aware datetimes · Issue ...
This issue is not isolated inside the function. It permeates outside of the function. It seems to start occurring after you use search_dates...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
andmodified: 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 andmodified = modified.replace(tzinfo=None)
Line 55However 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).I use ReviewBoard-1.7.25,after i comment a reviewrequest,a error occurred(other reviewrequest no error,only reviewrequest 118 error).what can i do to solve reviewrequest 118.the following is the error message:
Traceback (most recent call last): File “/usr/local/lib/python2.7/site-packages/Django-1.4.22-py2.7.egg/django/core/handlers/base.py”, line 109, in get_response response = callback(request, *callback_args, **callback_kwargs) File “/usr/local/lib/python2.7/site-packages/ReviewBoard-1.7.25-py2.7.egg/reviewboard/accounts/decorators.py”, line 20, in _check return login_required(view_func)(*args, **kwargs) File “/usr/local/lib/python2.7/site-packages/Djblets-0.7.33-py2.7.egg/djblets/auth/util.py”, line 47, in _checklogin return view_func(request, *args, **kwargs) File “/usr/local/lib/python2.7/site-packages/ReviewBoard-1.7.25-py2.7.egg/reviewboard/site/decorators.py”, line 35, in _check return view_func(request, local_site=local_site, *args, **kwargs) File “/usr/local/lib/python2.7/site-packages/ReviewBoard-1.7.25-py2.7.egg/reviewboard/reviews/views.py”, line 450, in review_detail if latest_reply and last_visited and last_visited < latest_reply: TypeError: can’t compare offset-naive and offset-aware datetimes