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?
I have become used to having to do this - if self.pool.get(model): m = self.pool.get(model). Good to know its possible to just index self.pool.
That is quite a remarkable question.