Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #707 (closed defect: fixed)

Opened 11 years ago

Last modified 10 years ago

[PATCH][TEST]FloatCol not converted from string to float when using DataController.

Reported by: cleonello@… Owned by: anonymous
Priority: high Milestone:
Component: TurboGears Version:
Severity: major Keywords:
Cc:

Description

In TurboGears 0.9a1 and 0.9a2 FloatCol?'s do not get converted from strings to floats when a model instance is added/edited through the web with the DataController CRUD interface. IntCol? and DateTimeCol? do seem to be correctly converted. My model looks like this:

class First (SQLObject):
    name = StringCol(length=32)
    date = DateTimeCol()
    ints = IntCol()
    floats = FloatCol()

To my controllers.py I added:

from turbogears.fastdata import DataController
from turbogears.fastdata.datawidgets import FastDataGrid

and

    first = DataController(sql_class=First, list_widget=FastDataGrid())

When I try to add or edit a model instance with the web browser, I get the following traceback:

31/Mar/2006:22:47:36 HTTP INFO Page handler: <bound method DataController.create of <turbogears.fastdata.datacontroller.DataController object at 0x2046170>>
Traceback (most recent call last):
  File "/sw/lib/python2.4/site-packages/CherryPy-2.2.0rc1-py2.4.egg/cherrypy/_cphttptools.py", line 99, in _run
    self.main()
  File "/sw/lib/python2.4/site-packages/CherryPy-2.2.0rc1-py2.4.egg/cherrypy/_cphttptools.py", line 248, in main
    body = page_handler(*virtual_path, **self.params)
  File "<string>", line 3, in create
  File "/sw/lib/python2.4/site-packages/TurboGears-0.9a2-py2.4.egg/turbogears/controllers.py", line 143, in validate
    return errorhandling.run_with_errors(errors, func, *args, **kw)
  File "/sw/lib/python2.4/site-packages/TurboGears-0.9a2-py2.4.egg/turbogears/errorhandling.py", line 96, in run_with_errors
    output = func(self, *args, **kw)
  File "<string>", line 3, in create
  File "/sw/lib/python2.4/site-packages/TurboGears-0.9a2-py2.4.egg/turbogears/controllers.py", line 207, in expose
    output = database.run_with_transaction(expose._expose,func, accept, allow_json, allow_json_from_config,*args, **kw)
  File "/sw/lib/python2.4/site-packages/TurboGears-0.9a2-py2.4.egg/turbogears/database.py", line 216, in run_with_transaction
    retval = func(*args, **kw)
  File "<string>", line 5, in _expose
  File "/sw/lib/python2.4/site-packages/TurboGears-0.9a2-py2.4.egg/turbogears/controllers.py", line 228, in <lambda>
    expose._expose.when(rule)(lambda _func, accept, allow_json, allow_json_from_config,*args,**kw: _execute_func(
  File "/sw/lib/python2.4/site-packages/TurboGears-0.9a2-py2.4.egg/turbogears/controllers.py", line 246, in _execute_func
    output = errorhandling.try_call(func, *args, **kw)
  File "/sw/lib/python2.4/site-packages/TurboGears-0.9a2-py2.4.egg/turbogears/errorhandling.py", line 59, in try_call
    output = func(self, *args, **kw)
  File "/sw/lib/python2.4/site-packages/TurboGears-0.9a2-py2.4.egg/turbogears/fastdata/datacontroller.py", line 239, in create
    obj = self.sql_class(**data)
  File "/sw/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1613-py2.4.egg/sqlobject/declarative.py", line 92, in _wrapper
    return_value = fn(self, *args, **kwargs)
  File "/sw/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1613-py2.4.egg/sqlobject/main.py", line 1197, in __init__
    self._create(id, **kw)
  File "/sw/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1613-py2.4.egg/sqlobject/main.py", line 1221, in _create
    self.set(**kw)
  File "/sw/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1613-py2.4.egg/sqlobject/main.py", line 1080, in set
    kw[name] = dbValue = from_python(value, self._SO_validatorState)
  File "/sw/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1613-py2.4.egg/sqlobject/col.py", line 671, in from_python
    (self.name, type(value), value), value, state)
Invalid: expected a float in the FloatCol 'floats', got <type 'unicode'> u'2.2' instead

Attachments

707.diff Download (2.9 KB) - added by Joost 11 years ago.
added FloatCol? support and proper create validation

Change History

comment:1 Changed 11 years ago by cleonello@…

  • Summary changed from FloatCol not converted from float to string when using DataController. to FloatCol not converted from string to float when using DataController.

Fixed typo in summary.

Changed 11 years ago by Joost

added FloatCol? support and proper create validation

comment:2 Changed 11 years ago by anonymous

  • Summary changed from FloatCol not converted from string to float when using DataController. to [PATCH][TEST]FloatCol not converted from string to float when using DataController.

comment:3 Changed 11 years ago by simon

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

Committed in [1121]. Thanks!

Note: See TracTickets for help on using tickets.