Skip to content

Trac: TypeError: can't compare datetime.datetime to str

This problem appears when sorting closed tickets by their "modified" field. Example. The source of the problem appears to be that a few old tickets don't have a "modified" time (changetime). Instead their "changetime" field seems to be set to the empty string.

Apparently similar issues have been known to the Trac developers for a while: https://trac.edgewall.org/ticket/12029.

How to Reproduce

While doing a GET operation on /query, Trac issued an internal error.

(please provide additional details here)

Request parameters:

{u'col': [u'id', u'changetime'],
 u'desc': u'1',
 u'order': u'changetime',
 u'page': u'2',
 u'status': u'closed'}

User agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/64.0.3282.167 Chrome/64.0.3282.167 Safari/537.36

System Information

System information not available

Enabled Plugins

Plugin information not available

Interface Customization

Interface customization information not available

Python Traceback

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/trac/web/main.py", line 623, in _dispatch_request
    dispatcher.dispatch(req)
  File "/usr/local/lib/python2.7/dist-packages/trac/web/main.py", line 239, in dispatch
    resp = chosen_handler.process_request(req)
  File "/usr/local/lib/python2.7/dist-packages/trac/ticket/query.py", line 1000, in process_request
    return self.display_html(req, query)
  File "/usr/local/lib/python2.7/dist-packages/trac/ticket/query.py", line 1117, in display_html
    data = query.template_data(context, tickets, orig_list, orig_time, req)
  File "/usr/local/lib/python2.7/dist-packages/trac/ticket/query.py", line 776, in template_data
    elif ticket['changetime'] > orig_time:
TypeError: can't compare datetime.datetime to str
Trac metadata
Trac field Value
Version
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Trac & Git
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information