#179 integer and float values of 0 get converted to None

closed-works-for-me
None
5
2006-06-07
2006-06-05
No

There is a problem with the validation/conversion of
integer and float columns. When creating objects with
IntCol and FloatCols, values of 0 are converted to
None. String values are converted properly, however.

An example:

class test(SQLObject):
fcol=FloatCol()
icol=IntCol()

t = test(fcol=3.2, icol=1)
print t

<test 10L fcol=3.2000000000000002 icol=1>

t = test(fcol=0.0, icol=0)
print t

<test 11L fcol=None icol=None>

t = test(fcol='0.0', icol='0')
print t

<test 14L fcol=0.0 icol=0>

I am using SQLObject rev 1675, python2.4, formencode
0.5.1, postgresql 8.1.

Discussion

  • Oleg Broytman

    Oleg Broytman - 2006-06-07

    Logged In: YES
    user_id=4799

    You examples produce the followin results for me:

    SQLite:
    <test 1 fcol=3.2000000000000002 icol=1>
    <test 2 fcol=0.0 icol=0> # No problem here, right?

    Traceback (most recent call last):
    File "./test1.py", line 23, in ?
    t = test(fcol='0.0', icol='0')
    File
    "./SQLObject-0.7.1dev_r1684-py2.4.egg/sqlobject/declarative.py",
    line 92, in _wrapper
    File
    "./SQLObject-0.7.1dev_r1684-py2.4.egg/sqlobject/main.py",
    line 1197, in __init__
    File
    "./SQLObject-0.7.1dev_r1684-py2.4.egg/sqlobject/main.py",
    line 1221, in _create
    File
    "./SQLObject-0.7.1dev_r1684-py2.4.egg/sqlobject/main.py",
    line 1080, in set
    File
    "./SQLObject-0.7.1dev_r1684-py2.4.egg/sqlobject/col.py",
    line 671, in from_python
    formencode.api.Invalid: expected a float in the FloatCol
    'fcol', got <type 'str'> '0.0' instead

    Postgres 7.4:
    <test 1L fcol=3.2000000000000002 icol=1>
    <test 2L fcol=0.0 icol=0> # Ok?

    Traceback (most recent call last):
    File "./test1.py", line 23, in ?
    t = test(fcol='0.0', icol='0')
    File
    "./SQLObject-0.7.1dev_r1684-py2.4.egg/sqlobject/declarative.py",
    line 92, in _wrapper
    File
    "./SQLObject-0.7.1dev_r1684-py2.4.egg/sqlobject/main.py",
    line 1197, in __init__
    File
    "./SQLObject-0.7.1dev_r1684-py2.4.egg/sqlobject/main.py",
    line 1221, in _create
    File
    "./SQLObject-0.7.1dev_r1684-py2.4.egg/sqlobject/main.py",
    line 1080, in set
    File
    "./SQLObject-0.7.1dev_r1684-py2.4.egg/sqlobject/col.py",
    line 671, in from_python
    formencode.api.Invalid: expected a float in the FloatCol
    'fcol', got <type 'str'> '0.0' instead

     
  • Oleg Broytman

    Oleg Broytman - 2006-06-07
    • assigned_to: nobody --> phd
    • status: open --> closed-works-for-me
     

Log in to post a comment.