[ORM] If field doesn't exist in browse, we have now an exception

Bug #541068 reported by Sebastien LANGE - http://www.Syleam.fr
6
This bug affects 1 person
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-services:[22]: File "/home/oerp/openerp/trunk/addons/base_calendar/base_calendar.py", line 337, in _compute_data
[2010-03-18 17:32:59,765] ERROR:web-services:[23]: if attdata.ref:
[2010-03-18 17:32:59,765] ERROR:web-services:[24]: File "/home/oerp/openerp/trunk_20100316/server/bin/osv/orm.py", line 275, in __getattr__
[2010-03-18 17:32:59,765] ERROR:web-services:[25]: raise AttributeError(e)
[2010-03-18 17:32:59,765] ERROR:web-services:[26]: AttributeError: 'Field ref not found in browse_record(calendar.attendee, 2)'

I think we have two possibility, revert the code of server or modify all modules

Revision history for this message
Xavier (Open ERP) (xmo-deactivatedaccount) wrote :

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

Revision history for this message
Sebastien LANGE - http://www.Syleam.fr (alnslang) wrote :

I propose to close this bug ?

Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :

Hello, I vote to close this bug too. Right, I'm even closing it, re-open it if you prefer.

Revision history for this message
Borja López Soilán (NeoPolus) (borjals) wrote :

"since `browse_record` can also be accessed as a dict it might be nice to add a .get(key, default=None) method as well".

Didn't know that the browse_records could be accessed as a dict :) but having a ".get()" would be nice (it makes code very readable).

Revision history for this message
Borja López Soilán (NeoPolus) (borjals) wrote :

By the way, see the related bug 596202 - hasattr does not currently work on OpenERP's browse_records!

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.