alfonsodg / demo-web2py

Apache License 2.0
0 stars 0 forks source link

dal.py bool check fails if value type is 'Boolean' from external datasource #173

Closed alfonsodg closed 10 years ago

alfonsodg commented 10 years ago

From gr...@jingojango.net on February 04, 2011 17:57:24

I have an external data source that is not web2py controlled. It uses true boolean field types and so results return python True or False 'bool' types. This causes a traceback in dal.py.

Code in dal.py:

1209: elif field_type == 'boolean': 1210: if value == True or value.strip().lower() == 't': 1211: colset[fieldname] = True 1212: else: 1213: colset[fieldname] = False

Traceback (most recent call last): File "/Users/grutz/src/web2py/gluon/restricted.py", line 188, in restricted exec ccode in environment File "/Users/grutz/src/web2py/applications/newapp/controllers/default.py", line 104, in

File "/Users/grutz/src/web2py/gluon/globals.py", line 95, in self._caller = lambda f: f() File "/Users/grutz/src/web2py/gluon/tools.py", line 2301, in f return action(_a, *_b) File "/Users/grutz/src/web2py/applications/newapp/controllers/default.py", line 27, in ulog_select return dict(rows=grid()) File "applications/newapp/modules/webgrid.py", line 224, in call orderby=sortby, groupby=groupby) File "/Users/grutz/src/web2py/gluon/dal.py", line 4590, in select return self.db._adapter.select(self.query,fields,attributes) File "/Users/grutz/src/web2py/gluon/dal.py", line 1012, in select return self.parse(rows,self._colnames) File "/Users/grutz/src/web2py/gluon/dal.py", line 1210, in parse if value == True or value.strip().lower() == 't':

type(value) <type 'bool'>

Field definition in model:

Field('tcp_urg', type='boolean'),

Database: postgresql, Field type: boolean

Solution idea: Perform value.strip().lower() check only after validating variable type:

if type(value) == type(bool()): if value == True ....

and

if type(value) == type(str()) if value.strip().lower() == 't':

Original issue: http://code.google.com/p/web2py/issues/detail?id=175

alfonsodg commented 10 years ago

From gr...@jingojango.net on February 04, 2011 15:59:26

I changed line 1210 to this and it seems to work:

                if (type(value) == type(bool()) and value == True) or (type(value) == type(str()) and value.strip().lower() == 't'):
alfonsodg commented 10 years ago

From roman.imankulov on February 05, 2011 09:50:24

Just to mention that the bug was introduced by the changeset 65e9f493d204. Hope this will be fixed soon in trunk.

alfonsodg commented 10 years ago

From massimo....@gmail.com on February 05, 2011 20:45:27

I think this is fixed. Please let me know if not.

Status: Fixed