Hi Max,

That's indeed a FE bug, as you can see the only point where TG widgets
kick in is to call to_python on the form Schema.

Regarding your fix, maybe you can post it on FE trac and in the
meanwhile put it inside tg.validators to fix the bug (add a note so
that we track it maybe), Kevin?

Ciao
Michele

Max Ischenko wrote:
> When I'm trying to use a FileField I got this error:
>
>   File "d:\projects\3rd-party\turbogears\turbogears\controllers.py", line 
> 110, in validate
>     kw.update(form.validate(value))
>   File "d:\projects\3rd-party\turbogears\turbogears\widgets\forms.py", line 
> 865, in validate
>     return self.validator.to_python(value, state)
>   File 
> "c:\python24\lib\site-packages\formencode-0.4-py2.4.egg\formencode\api.py", 
> line 308, in to_python
>     value = tp(value, state)
>   File 
> "c:\python24\lib\site-packages\formencode-0.4-py2.4.egg\formencode\schema.py",
>  line 132, in _to_python
>     new[name] = validator.to_python(value, state)
>   File 
> "c:\python24\lib\site-packages\formencode-0.4-py2.4.egg\formencode\api.py", 
> line 297, in to_python
>     if not value and value != 0:
>   File "C:\Python24\lib\cgi.py", line 625, in __len__
>     return len(self.keys())
>   File "C:\Python24\lib\cgi.py", line 601, in keys
>     raise TypeError, "not indexable"
> TypeError: not indexable
>
> Looks like a formencode/cgi bug to me but nevertheless, it renders stock 
> FileField unusable.
>
> Using formencode's FieldStorageUploadConverter validator doesn't help either 
> as the bug happens before it is run.
>
> To workaround the bug I come up with this validator class instead:
>
> class FileUploadConverter(validators.FancyValidator):
>     def to_python(self, value, state=None):
>         if isinstance(value, cgi.FieldStorage):
>             if value.filename:
>                 return value
>             raise validators.Invalid('invalid', value, state)
>         else:
>             return value
>
> I'm not 100% whether this should be reported to formencode' bug tracker or it 
> has something with TG/CherryPy so decided to post here first.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears-trunk
-~----------~----~----~----~------~----~------~--~---

Reply via email to