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 #1365 (closed defect: invalid)

Opened 12 years ago

Last modified 12 years ago

Fixed - SQLObject not saving models with Integer columns

Reported by: AZMel Owned by:
Priority: high Milestone: 1.0.2
Component: unassigned Version: 1.0.1
Severity: normal Keywords:
Cc:

Description

My Setup

TurboGears Version Info

    * TurboGears 1.0.1
    * configobj 4.4.0
    * RuleDispatch 0.5a0
    * setuptools 0.6c5
    * FormEncode 0.5.1
    * cElementTree 1.0.5-20051216
    * PasteScript 1.1
    * elementtree 1.2.6-20050316
    * simplejson 1.3
    * CherryPy 2.2.1
    * TurboKid 0.9.9
    * TurboCheetah 0.9.5
    * TurboJson 1.0
    * PyProtocols 1.0a0
    * Cheetah 2.0rc7
    * PasteDeploy 1.1
    * Paste 1.2.1
    * kid 0.9.5
    * Cheetah 2.0rc7

Installed Plugins
Identity Providers

    * sqlobject (TurboGears 1.0.1)
    * sqlalchemy (TurboGears 1.0.1)

tg-admin Commands

    * info (TurboGears 1.0.1)
    * shell (TurboGears 1.0.1)
    * quickstart (TurboGears 1.0.1)
    * update (TurboGears 1.0.1)
    * sql (TurboGears 1.0.1)
    * i18n (TurboGears 1.0.1)
    * toolbox (TurboGears 1.0.1)
    * crud (tgcrud 1.0Beta2)

Visit Managers

    * sqlobject (TurboGears 1.0.1)
    * sqlalchemy (TurboGears 1.0.1)

Template Engines

    * kid (TurboKid 0.9.9)
    * cheetah (TurboCheetah 0.9.5)
    * json (TurboJson 1.0)

Widget Packages

    * tgpaginate (TGPaginate 0.1a0.dev-r627)
    * scriptaculous (Scriptaculous 1.6.2)

TurboGears Extensions

    * visit (TurboGears 1.0.1)
    * identity (TurboGears 1.0.1)


The Error

500 Internal error

The server encountered an unexpected condition which prevented it from fulfilling the request.

Page handler: <bound method reach.save of <ycwuadispatch.reach.controllers.reach object at 0xb73c252c>>
Traceback (most recent call last):
  File "/var/lib/python-support/python2.4/cherrypy/_cphttptools.py", line 105, in _run
    self.main()
  File "/var/lib/python-support/python2.4/cherrypy/_cphttptools.py", line 254, in main
    body = page_handler(*virtual_path, **self.params)
  File "<string>", line 3, in save
  File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/turbogears/controllers.py", line 173, in validate
    return errorhandling.run_with_errors(errors, func, *args, **kw)
  File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/turbogears/errorhandling.py", line 113, in run_with_errors
    return func(self, *args, **kw)
  File "<string>", line 3, in save
  File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/turbogears/controllers.py", line 334, in expose
    output = database.run_with_transaction(
  File "<string>", line 5, in run_with_transaction
  File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/turbogears/database.py", line 302, in so_rwt
    retval = func(*args, **kw)
  File "<string>", line 5, in _expose
  File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/turbogears/controllers.py", line 351, in <lambda>
    mapping, fragment, args, kw)))
  File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/turbogears/controllers.py", line 378, in _execute_func
    output = errorhandling.try_call(func, *args, **kw)
  File "/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/turbogears/errorhandling.py", line 73, in try_call
    return func(self, *args, **kw)
  File "/home/mirizarry/YCWUADispatch/ycwuadispatch/reach/controllers.py", line 120, in save
    setattr(record, attr, kw[attr])
  File "<string>", line 1, in <lambda>
  File "/usr/lib/python2.4/site-packages/SQLObject-0.7.3-py2.4.egg/sqlobject/main.py", line 1051, in _SO_setValue
    dbValue = from_python(value, self._SO_validatorState)
  File "/usr/lib/python2.4/site-packages/SQLObject-0.7.3-py2.4.egg/sqlobject/col.py", line 589, in from_python
    (self.name, type(value), value), value, state)
Invalid: expected an int in the IntCol 'cfs', got <type 'unicode'> u'100' instead

This is the model in question:

class Reach(SQLObject):
    class sqlmeta:
      table = "Reach"
    reach = UnicodeCol(length=45)
    turnout = UnicodeCol(length=45)
    serialnumber = UnicodeCol(length=8)
    cfs = IntCol()

Change History

comment:1 Changed 12 years ago by AZMel

  • Version changed from 1.0 to 1.0.1

comment:2 Changed 12 years ago by AZMel

  • Status changed from new to closed
  • Resolution set to invalid
  • Summary changed from SQLObject not saving models with Integer columns to Fixed - SQLObject not saving models with Integer columns

Solved it. I added a validator, now that I understand how they work. My code now looks like this: (Notice I changed ReachSchema?() to define the columns and ReachForm?() to use ReachSchema?() as a validator.

class ReachFields?(WidgetsList?):

"""Replace to your Fields""" reach = TextField?(label="reach") turnout = TextField?(label="turnout") serialnumber = TextField?(label="serialnumber") cfs = TextField?(label="cfs")

class ReachSchema?(validators.Schema):

""" separate validation schema from the fields definition make it possible to define a more complex schema that involves field dependency or logical operators """ reach = validators.String(not_empty=True, max=45) turnout = validators.String(not_empty=False, max=45) serialnumber = validators.String(not_empty=False, max=8) cfs = validators.Number()

class ReachForm?(TableForm?):

#name="Reach" fields = ReachFields?() validator = ReachSchema?() # define schema outside of ReachFields? #method="post" submit_text = "Create"

Note: See TracTickets for help on using tickets.