← Back to team overview

c2c-oerpscenario team mailing list archive

[Bug 684263] Re: Server ORM bug V5. Error when using function field (type : boolean, store=True)

 

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 :-)

** Patch added: "trunk patch"
   https://bugs.launchpad.net/openobject-server/+bug/684263/+attachment/1753284/+files/bug_684263_trunk.patch

** Changed in: openobject-server
   Importance: Undecided => Low

** Changed in: openobject-server
       Status: New => Confirmed

** Changed in: openobject-server
     Assignee: (unassigned) => Jay (OpenERP) (jvo-openerp)

-- 
You received this bug notification because you are a member of C2C
OERPScenario, which is subscribed to the OpenERP Project Group.
https://bugs.launchpad.net/bugs/684263

Title:
  Server ORM bug V5. Error when using function field (type : boolean, store=True)

Status in OpenObject Server:
  Confirmed

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.





References