Fields.function : wrong accessors for fields of type boolean,integer,integer_big (DB stores null instead of False,0,0 respectively)

Bug #684263 reported by Sébastien BEAU - http://www.akretion.com
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Status tracked in Trunk
5.0
Fix Released
Low
Jay Vora (Serpent Consulting Services)
Trunk
Fix Released
Low
OpenERP's Framework R&D

Bug Description

Hi
We are working on fleet_maintenance. (not the version in extra-addons but this version : https://code.launchpad.net/~akretion-team/openobject-addons/fleet_maintenance_anevia)
We use function.fields with the type boolean and the option store=True.

When we check in the database, we don't see any value 'False' in the column of our field. Only the values Null or True are present. After some code inspection, we found where is the bug.

Indeed, on a standard field boolean, the value is force to "True" or "False". On a function field, the function called to set the field to "False" or "True" returns a wrong result : it returns the value "True" or "None".

To see what is wrong, add some print in the orm.py line 3003 :

 result = self._columns[f].get(cr, self, ids, f, uid, context=context)
                    for id,value in result.items():
+ print 'value', value
+ print 'f', f
+ print 'symbol type', self._columns[f]._type
+ print 'self._columns[f]._symbol_set[1](True)',self._columns[f]._symbol_set[1](True)
+ print 'self._columns[f]._symbol_set[1](False)',self._columns[f]._symbol_set[1](False)
                        if self._columns[f]._type in ('many2one', 'one2one'):
                            try:
                                value = value[0]
                            except:
                                pass

The result of the print are :
value False
f is_expired
symbol type boolean
self._columns[f]._symbol_set[1](True) True
self._columns[f]._symbol_set[1](False) None

In this case (only for a function field with the type boolean, not for a pure boolean field) the method _symbol_set[1](False) returns "None" and not "False".

I try to modify the _symbol_set method in field.py
class boolean(_column):
    _type = 'boolean'
    _symbol_c = '%s'
    _symbol_f = lambda x: x and 'True' or 'False'
    _symbol_set = (_symbol_c, _symbol_f)

with incorrect value in order to crash openerp, but it doesn't use this code for a function fields. Here is the problem : it should execute this code as it's a boolean field.

Hope reporting this bug will help you.

For people which are affected by this bug you can use this patch.

Tags: maintenance
Revision history for this message
Sébastien BEAU - http://www.akretion.com (sebastien.beau) wrote :
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Hello Sébastien,

Indeed, the problem is that in v5 the default _symbol_set accessors were used for function fields of type boolean.
This was fixed a long time ago in v6. I'm attaching the patch that was used in v6, because the approach is possible in v5 (the patch won't probably apply cleanly because the surrounding lines have changed, though, but the idea is to handle the case of boolean types at the end of the __init__ of fields.function in the same way it was done for integer types.)

I'm assigning this to the maintenance team in case they consider the fix important and safe enough to be applied to the 5.0 branch (I think it's low-risk but also low priority). Otherwise they may close it as Fix Released in v6.0.

Thanks for raising this issue to attention :-)

Changed in openobject-server:
assignee: nobody → Jay (OpenERP) (jvo-openerp)
importance: Undecided → Low
status: New → Confirmed
tags: added: maintenance
summary: - Server ORM bug V5. Error when using function field (type : boolean,
+ [5.0] ORM: Error when using boolean function field (type : boolean,
store=True)
summary: - [5.0] ORM: Error when using boolean function field (type : boolean,
- store=True)
+ [5.0] ORM: NULL stored instead of False when using boolean function
+ field (type : boolean, store=True)
Changed in openobject-server:
status: Confirmed → In Progress
summary: - [5.0] ORM: NULL stored instead of False when using boolean function
- field (type : boolean, store=True)
+ Fields.function : wrong accessors for fields of type
+ boolean,integer,integer_big (DB stored null instead of False,0,0
+ respectively)
summary: Fields.function : wrong accessors for fields of type
- boolean,integer,integer_big (DB stored null instead of False,0,0
+ boolean,integer,integer_big (DB stores null instead of False,0,0
respectively)
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Thanks for reporting Sébastien.
It has been fixed by revision 2169 <email address hidden>.

Revision history for this message
Yogesh (SerpentCS) (yogesh-serpentcs) wrote :

Hello,

It has been fixed into trunk https://code.launchpad.net/~openerp-dev/openobject-server/funciton_field_accessors by:
Revision ID: <email address hidden>
Revno: 3233

Thanks.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.