Trac: TypeError: can't compare datetime.datetime to str
This problem appears when sorting closed tickets by their "modified" field. [Example](https://ghc.haskell.org/trac/ghc/query?status=closed&col=id&col=changetime&desc=1&order=changetime). 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
```
<details><summary>Trac metadata</summary>
| 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 | |
</details>
<!-- {"blocked_by":[],"summary":"Trac: TypeError: can't compare datetime.datetime to str","status":"New","operating_system":"","component":"Trac & Git","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"hvr"},"version":"","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"This problem appears when sorting closed tickets by their \"modified\" field. [https://ghc.haskell.org/trac/ghc/query?status=closed&col=id&col=changetime&desc=1&order=changetime 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.\r\n\r\nApparently similar issues have been known to the Trac developers for a while: https://trac.edgewall.org/ticket/12029.\r\n\r\n==== How to Reproduce ====\r\n\r\nWhile doing a GET operation on `/query`, Trac issued an internal error.\r\n\r\n''(please provide additional details here)''\r\n\r\nRequest parameters:\r\n{{{\r\n{u'col': [u'id', u'changetime'],\r\n u'desc': u'1',\r\n u'order': u'changetime',\r\n u'page': u'2',\r\n u'status': u'closed'}\r\n}}}\r\n\r\nUser 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`\r\n\r\n==== System Information ====\r\n''System information not available''\r\n\r\n==== Enabled Plugins ====\r\n''Plugin information not available''\r\n\r\n==== Interface Customization ====\r\n''Interface customization information not available''\r\n\r\n==== Python Traceback ====\r\n{{{\r\nTraceback (most recent call last):\r\n File \"/usr/local/lib/python2.7/dist-packages/trac/web/main.py\", line 623, in _dispatch_request\r\n dispatcher.dispatch(req)\r\n File \"/usr/local/lib/python2.7/dist-packages/trac/web/main.py\", line 239, in dispatch\r\n resp = chosen_handler.process_request(req)\r\n File \"/usr/local/lib/python2.7/dist-packages/trac/ticket/query.py\", line 1000, in process_request\r\n return self.display_html(req, query)\r\n File \"/usr/local/lib/python2.7/dist-packages/trac/ticket/query.py\", line 1117, in display_html\r\n data = query.template_data(context, tickets, orig_list, orig_time, req)\r\n File \"/usr/local/lib/python2.7/dist-packages/trac/ticket/query.py\", line 776, in template_data\r\n elif ticket['changetime'] > orig_time:\r\nTypeError: can't compare datetime.datetime to str\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->
issue