#75 exception called b/c of issue with millisecs in date string

open-invalid
Oleg Broytman
None
5
2006-11-10
2006-10-16
ptwobrussell
No

A patch to fix an issue caused when pgdb returns a
date/time string that contains milliseconds in it:

col.py.orig is the original file. col.py is the updated
file

Patch is inline below:

--- col.py.orig 2006-10-16 14:11:30.000000000 -0400
+++ col.py 2006-10-16 14:13:28.000000000 -0400
@@ -941,7 +941,8 @@
else:
return
datetime.time(value.hour, value.minute, int(value.second))
try:
- stime = time.strptime(value, self.format)
+ #postgres might return a time value
with milliseconds. strip it or else change the format
string
+ stime =
time.strptime(value[value.rfind('.')], self.format)
except:
raise validators.Invalid("expected an
date/time string of the '%s' format in the DateTimeCol
'%s', got %s %r instead" % \ (self.format, self.name,
type(value), value), value, state)

Discussion

  • Oleg Broytman
    Oleg Broytman
    2006-11-10

    • assigned_to: nobody --> phd
    • status: open --> open-invalid
     
  • Oleg Broytman
    Oleg Broytman
    2006-11-10

    Logged In: YES
    user_id=4799

    value[value.rfind('.')]? There have to be a colon somewhere:
    value[:value.rfind('.')], I suppose?

     
  • ptwobrussell
    ptwobrussell
    2006-11-11

    Logged In: YES
    user_id=1622325

    Yea, basically, this approach just chops off the "." and
    everything after it. Sorry about that. Don't know how the
    ":" didn't make it through. I generated the patch from my
    working copy. Weird.

     
  • Oleg Broytman
    Oleg Broytman
    2006-11-13

    Logged In: YES
    user_id=4799

    Even with the colon the patch is invalid. It cuts the last
    digit if there is no a dot. See:

    > python
    Python 2.4.4 (#1, Oct 23 2006, 18:00:38)
    [GCC 3.4.4 20050314 (prerelease) (Debian 3.4.3-13sarge1)] on
    linux2
    Type "help", "copyright", "credits" or "license" for more
    information.
    >>> s = "20:55"
    >>> s[:s.find('.')]
    '20:5'

    The problem you are trying to solve is a real problem but
    IWBN if you produce a patch that works for other people.