Comment 1 for bug 541068

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