Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
10967 Lượt xem

In almost all uses of self.pool.get(model) the Nonereturn 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?

Ảnh đại diện
Huỷ bỏ

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.

Câu trả lời hay nhất

I think since __getitem__() is added the core modules was not refactored.

Ảnh đại diện
Huỷ bỏ
Tác giả

Maybe, but even in new modules, pool is always accessed using the get() method.

Câu trả lời hay nhất

OpenERP Since a begins uses self.pool.get(model).

First thing is to understand this ERP architecture,

here modular approach and dependencies are well maintained.

So when you try to use any dependent module you must have add in depends at __openerp__.py file. It mean depending module always be their no need to worry about ‘None’ .

Whenever you try self.pool.get(model), it mean as logically you try to use existing module’s model or dependent model. Here no need to worry about it return None.

Source : http://goo.gl/qdAPD4 
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 10 20
12660
2
thg 8 25
187
0
thg 8 25
295
1
thg 8 25
685
1
thg 8 25
531