Ticket #44 (closed defect: fixed)
Turbogears fails to raise a validators.Invalid exception.
| Reported by: | skrikstone@… | Owned by: | anonymous |
|---|---|---|---|
| Priority: | high | Milestone: | 0.8a6 |
| Component: | TurboGears | Version: | 0.8 |
| Severity: | critical | Keywords: | |
| Cc: |
Description
Traceback when no validation_error method is defined and a validator is used:
Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/CherryPy-2.1.0_rc2-py2.4.egg/cherrypy/_cphttptools.py", line 271, in run
main()
File "/usr/lib/python2.4/site-packages/CherryPy-2.1.0_rc2-py2.4.egg/cherrypy/_cphttptools.py", line 502, in main
body = page_handler(*args, **cherrypy.request.paramMap)
File "/usr/lib/python2.4/site-packages/TurboGears-0.8a3-py2.4.egg/turbogears/controllers.py", line 119, in newfunc
raise turbogearsvalid.Invalid(str(errors))
TypeError: __init__() takes at least 4 arguments (2 given)
The problem is that the formencode.validators.Invalid API has changed. Also, IMHO, the error passed to the custom validation_error method is missing useful information.
To fix, apply simple 2 line patch to controllers.py
Change History
comment:2 Changed 7 years ago by kevin
I tried applying this patch, but there is now a failing test: ====================================================================== ERROR: Data can be converted and validated with formencode.Schema instance
Traceback (most recent call last):
File "/Users/tazzzzz/projects/turbogears/turbogears/tests/test_controllers.py", line 171, in test_validationwithschema
assert "missing" in cherrypy.root.errorslastname?.msg.lower()
AttributeError?: 'str' object has no attribute 'msg'
I don't have more time to look at this right now.
comment:3 Changed 7 years ago by kevin
- Status changed from new to closed
- Resolution set to fixed
- Milestone set to 0.9
I just undid the first of the two lines that were changed and all was well. This is checked in now.
comment:4 Changed 6 years ago by nic at bellamy dot co dot nz
- Status changed from closed to reopened
- Resolution fixed deleted
- Milestone changed from 0.9 to 0.8
Reopened with milestone set to 0.8 as this problem, along with ticket #190, completely break validators in the current download of TurboGears 0.8a5 + FormEncode 0.4.
I realise everyone is hard at work on 0.9, but major breakages in 0.8a5 are not going to inspire confidence in the userbase :-)
Patch:
--- controllers.py.org 2005-10-17 15:07:23.000000000 -0400 +++ controllers.py 2005-10-17 15:07:46.000000000 -0400 @@ -111,12 +111,12 @@ try: kw = validators.to_python(kw) except turbogearsvalid.Invalid, error: - errors = error.error_dict + errors = error.unpack_errors() if errors: if hasattr(self, "validation_error"): output = self.validation_error(func.func_name, kw, errors) else: - raise turbogearsvalid.Invalid(str(errors)) + raise turbogearsvalid.Invalid(str(errors), kw, None) else: output = func(self, *args, **kw) return controllers._process_output(tg_format, output, html)