Fields.function : wrong accessors for fields of type boolean,integer,integer_big (DB stores null instead of False,0,0 respectively)
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:/
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[
+ print 'value', value
+ print 'f', f
+ print 'symbol type', self._columns[
+ print 'self._
+ print 'self._
The result of the print are :
value False
f is_expired
symbol type boolean
self._columns[
self._columns[
In this case (only for a function field with the type boolean, not for a pure boolean field) the method _symbol_
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: | 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) |
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 :-)