Modify

Opened 7 years ago

Closed 7 years ago

Last modified 2 years ago

#2247 closed defect (worksforme)

TypeError: can't compare datetime.datetime to float

Reported by: george@… Owned by: hvr
Priority: normal Component: GitPlugin
Severity: critical Keywords:
Cc: Trac Release: 0.11

Description

How to Reproduce

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

Request parameters:

{'path': '/'}

System Information

Trac 0.11dev-r6139
Python 2.4.3 (#2, Oct 6 2006, 08:02:16)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)]
setuptools 0.6c1
SQLite 3.2.8
pysqlite 2.0.5
Genshi 0.4.4

Python Traceback

Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/Trac-0.11dev_r6139-py2.4.egg/trac/web/main.py", line 386, in dispatch_request
    dispatcher.dispatch(req)
  File "/usr/lib/python2.4/site-packages/Trac-0.11dev_r6139-py2.4.egg/trac/web/main.py", line 195, in dispatch
    resp = chosen_handler.process_request(req)
  File "/usr/lib/python2.4/site-packages/Trac-0.11dev_r6139-py2.4.egg/trac/versioncontrol/web_ui/browser.py", line 358, in process_request
    node.get_properties()),
  File "/usr/lib/python2.4/site-packages/Trac-0.11dev_r6139-py2.4.egg/trac/versioncontrol/web_ui/browser.py", line 400, in _render_dir
    timerange.insert(dt)
  File "/usr/lib/python2.4/site-packages/Trac-0.11dev_r6139-py2.4.egg/trac/versioncontrol/web_ui/browser.py", line 178, in insert
    self.oldest = min(self.oldest, datetime)
TypeError: can't compare datetime.datetime to float

Attachments (0)

Change History (6)

comment:1 Changed 7 years ago by straszheim

browser.py's class TimeRange needs to convert from floats to datetime objects in the same timezone. I don't understand this hack-fix but it does work on 0.11b1.

 class TimeRange(object):
   #other methods...

    def relative(self, dt):
        dt = datetime.fromtimestamp(dt, self.oldest.tzinfo)
        if self._total is None:
            self._total = float(self.seconds_between(self.newest, self.oldest))
        age = 1.0
        if self._total:
            age = self.seconds_between(dt, self.oldest) / self._total
        return age

    def insert(self, dt):
        self._total = None
        cnvrtd = datetime.fromtimestamp(dt, self.oldest.tzinfo)
        self.oldest = min(self.oldest, cnvrtd)
        self.newest = max(self.newest, cnvrtd)

so just convert those floats using datetime.fromtimestamp

comment:2 follow-up: Changed 7 years ago by straszheim

I take that back, there is a more straightforward fix. git_fs.py returns floats, but trac wants datetimes. git_fs.py gets

    import datetime as datetime
    from trac.util.datefmt import utc

at the top, and the line

      Changeset.__init__(self, sha, msg, user,time))

becomes

      Changeset.__init__(self, sha, msg, user,datetime.fromtimestamp(float(time),         utc))

comment:3 in reply to: ↑ 2 ; follow-up: Changed 7 years ago by hoodow@…

Replying to straszheim:

I take that back, there is a more straightforward fix. git_fs.py returns floats, but trac wants datetimes. git_fs.py gets

    import datetime as datetime
    from trac.util.datefmt import utc

at the top, and the line

      Changeset.__init__(self, sha, msg, user,time))

becomes

      Changeset.__init__(self, sha, msg, user,datetime.fromtimestamp(float(time),         utc))

Results in

   Trac detected an internal error:

   AttributeError: 'module' object has no attribute 'fromtimestamp'

here.

Trac 0.11dev-r6417
Python 2.5.1
setuptools 0.6c1
SQLite 3.4.1
pysqlite 2.3.5

comment:4 in reply to: ↑ 3 ; follow-up: Changed 7 years ago by anonymous

Try using

   Changeset.__init__(self, sha, msg, user, datetime.datetime.fromtimestamp(float(time), utc))

Replying to hoodow@moonitor.org:

Results in

Trac detected an internal error:

AttributeError: 'module' object has no attribute 'fromtimestamp'

here.

comment:5 in reply to: ↑ 4 Changed 7 years ago by hoodow@…

  • Resolution set to worksforme
  • Status changed from new to closed

Replying to anonymous:

Try using

   Changeset.__init__(self, sha, msg, user, datetime.datetime.fromtimestamp(float(time), utc))

Works, thanks.

comment:6 Changed 7 years ago by anonymous

has been incorporated into r3178

Add Comment

Modify Ticket

Action
as closed The owner will remain hvr.
The resolution will be deleted. Next status will be 'reopened'.
Author


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

 
Note: See TracTickets for help on using tickets.