Upgraded, but the error is still there. It's failing at the SQLFORM
validation in dal.py, I don't even get the chance to access session
variables myself. Also, list:integer fields leave an empty field behind
Is there a way from within the DAL to remove empty entries on list:integer
(as I can't rely on my users to not create empty entries when using the
form)?
def index():
"""
"""
form=SQLFORM.factory(
Field('employees', 'list:integer' ),
)
my_emps=[]
if form.process(session=None).accepted:
mvars=form.vars.employees
if mvars:
response.flash=myvars
for a in mvars:
my_emps.append(a)
else:
my_emps.append(mvars)
return dict(form=form, my_emps=my_emps)
Error:
Traceback (most recent call last):
File "/home/www-data/web2py/gluon/restricted.py", line 212, in restricted
exec ccode in environment
File "/home/www-data/web2py/applications/experiment/controllers/default.py",
line 196, in <module>
File "/home/www-data/web2py/gluon/globals.py", line 194, in <lambda>
self._caller = lambda f: f()
File "/home/www-data/web2py/applications/experiment/controllers/default.py",
line 127, in index
if form.process(session=None).accepted:
File "/home/www-data/web2py/gluon/html.py", line 2188, in process
self.validate(**kwargs)
File "/home/www-data/web2py/gluon/html.py", line 2127, in validate
if self.accepts(**kwargs):
File "/home/www-data/web2py/gluon/sqlhtml.py", line 1571, in accepts
self.vars.id = self.table.insert(**fields)
File "/home/www-data/web2py/gluon/dal.py", line 8598, in insert
ret = self._db._adapter.insert(self, self._listify(fields))
File "/home/www-data/web2py/gluon/dal.py", line 1203, in insert
query = self._insert(table,fields)
File "/home/www-data/web2py/gluon/dal.py", line 1194, in _insert
values = ','.join(self.expand(v, f.type) for f, v in fields)
File "/home/www-data/web2py/gluon/dal.py", line 1194, in <genexpr>
values = ','.join(self.expand(v, f.type) for f, v in fields)
File "/home/www-data/web2py/gluon/dal.py", line 1376, in expand
return str(self.represent(expression,field_type))
File "/home/www-data/web2py/gluon/dal.py", line 1805, in represent
obj = map(int,obj)
ValueError: invalid literal for int() with base 10: ''
On Thursday, June 20, 2013 2:31:51 PM UTC+3, Martin Barnard wrote:
>
> That code listing is from dal.py. I didn't really want to poke too much at
> that as I haven't had time to examine it too deeply.
>
> I should probably upgrade to latest web2py before trying anything else :)
>
> */scurries off to upgrade the server...*
>
> On Thursday, June 20, 2013 12:45:28 AM UTC+3, Niphlod wrote:
>>
>> it's a bug reproduceable only if you leave one empty field.
>> BTW, you're parsing it wrong.... given a single field filled with 1234,
>> you get [1,2,3,4] back.
>>
>> you should do
>>
>> vars = form.vars.employees
>> if vars:
>> if isinstance(vars, (list, tuple)):
>> for a in vars:
>> ids.append(a)
>> else:
>> ids.append(vars)
>>
>> Anyway, I'll submit an issue with the fix.
>>
>>>
>>> -
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.