[ORM] If field doesn't exist in browse, we have now an exception
Affects | Status | Importance | Assigned to | Milestone | ||
---|---|---|---|---|---|---|
Odoo Server (MOVED TO GITHUB) | Status tracked in Trunk | |||||
Trunk |
Invalid
|
Critical
|
Husen Daudi |
Bug Description
Since rev 2012, it's not possible to test if field exist in browse, for exemple in base_calendar module in line 337 :
if attdata.ref <= return :
[2010-03-18 17:32:59,765] ERROR:web-
[2010-03-18 17:32:59,765] ERROR:web-
[2010-03-18 17:32:59,765] ERROR:web-
[2010-03-18 17:32:59,765] ERROR:web-
[2010-03-18 17:32:59,765] ERROR:web-
I think we have two possibility, revert the code of server or modify all modules
> Since rev 2012, it's not possible to test if field exist in browse
Of course it is, use `hasattr(attdata, 'ref')` or `getattr(attdata, 'ref', None)` instead depending on the exact semantics of your call (now that I think about it, since `browse_record` can also be accessed as a dict it might be nice to add a .get(key, default=None) method as well), as you would with a normal python object. You might also be able to use `'ref' in attdata`, but I'm not actually sure it works (reading the source, its implementation seems strangely simplistic compared to that of `__getitem__`)
The former behavior was inconsistent (it would return None on some fields missing, but would throw an exception on others, and usually the wrong kind of exception) and impractical (it broke `hasattr` and `getattr`, and didn't allow differentiating between a field missing and a field set to None).