Quantcast
Channel: OpenERP Help - Individual question feed
Viewing all articles
Browse latest Browse all 39

Why pool.get(model) is used to get a model instance instead of pool[model]?

$
0
0
In almost all uses of `self.pool.get(model)` the `None`return value (missing model) is not handled. This usually leads to a very confusing exception later in other place in the form `AttributeError: 'NoneType' object has no attribute 'xxxxx'`. Sometimes, finding the error cause is not straightforward as the exception does not show the offending model name which may be from XML data or has been dynamically manipulated like in menu actions or just a missing dependency. To find the problem, I have to set a conditional breakpoint for the None value at the exception line and look up in the stack for the model name. Since the `Registry` class has `__getitem__()` method, I started to use `self.pool[model]` in my code to get an exception that shows the model name immediately in the form `KeyError: 'model.name'` instead of a confusing error later. My question is, why OpenERP server and core modules use the `pool.get()` method if the None value is not handled anyway?

Viewing all articles
Browse latest Browse all 39

Trending Articles