Modify

Opened 5 years ago

Last modified 5 years ago

#4930 new defect

[Patch] "TypeError: can't compare datetime.datetime to float" if search term appears in both wiki and attachments

Reported by: srl100@… Owned by: deltroo
Priority: normal Component: SearchAttachmentsPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.11

Description

If you have a search term that appears in both the wiki and an attachment, Trac throws an error
"TypeError: can't compare datetime.datetime to float".

My guess, from the error text, is that it is trying to sort the search results into date order, but is getting different date types from the different areas.

How to Reproduce

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

(please provide additional details here)

Request parameters:

{'attachments': u'on',
 'milestone': u'on',
 'noquickjump': u'1',
 'q': u'repositories',
 'ticket': u'on',
 'wiki': u'on'}

User Agent was: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032711 Ubuntu/8.10 (intrepid) Firefox/3.0.8

System Information

Trac 0.11.4
Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)
[GCC 4.3.2]
setuptools 0.6c9
SQLite 3.5.9
pysqlite 2.3.2
Genshi 0.5.1
jQuery: 1.2.6

Python Traceback

Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/web/main.py", line 435, in _dispatch_request
    dispatcher.dispatch(req)
  File "/usr/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/web/main.py", line 205, in dispatch
    resp = chosen_handler.process_request(req)
  File "/usr/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/search/web_ui.py", line 107, in process_request
    results.sort(lambda x,y: cmp(y[2], x[2]))
  File "/usr/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/search/web_ui.py", line 107, in <lambda>
    results.sort(lambda x,y: cmp(y[2], x[2]))
TypeError: can't compare datetime.datetime to float


Attachments (1)

4930_1.patch (315 bytes) - added by srl100@… 5 years ago.

Download all attachments as: .zip

Change History (3)

comment:1 Changed 5 years ago by anonymous

Sorted this with the following changes to searchattachments.py

from trac.util.datefmt import to_datetime

if os.path.exists (file):

< date = os.path.getmtime( file ))

date = to_datetime(os.path.getmtime( file ))

else:

Changed 5 years ago by srl100@…

comment:2 Changed 5 years ago by rjollos

  • Summary changed from Trac reports "TypeError: can't compare datetime.datetime to float" if search term appears in both wiki and attachments to [Patch] "TypeError: can't compare datetime.datetime to float" if search term appears in both wiki and attachments

Add Comment

Modify Ticket

Action
as new .
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.