When switching from OE 7.0 to OE 8.0, we found that many modules in our system could not be loaded, but errors occurred during import, later I found that the Addons of OE 8.0 was modified, and openerp was added when I imported my Addons. addons namespace. Why is OE 8.0 doing so? I found out the real reasons behind it:
Openerp 7.0 supports two import methods: Import <module> and import openerp. addons. <module> in this way, most of the import operations in our Addons are the first one. Now, when we migrate our Addons to 8.0, we find many cases of Cold' t load module, why?
1. First, we need to explain why openerp adopts two import methods. openerp does not use the default Python import mechanism, but hooks the python import mechanism, I made an importer of my own, that is, the two situations mentioned above.
2. Why is there only the second import openerp method available when the two import methods of 7.0 reach 8.0. addons. <module> this method does not support the first method. This is because of import conflicts. For example, a module in the python standard library is called resource, openerp also has such a module. If the first import method is used, module confusion may occur. Therefore, the openrp. Addons namespace must be added to the Addons namespace of openerp from 8.0.
3. Where is the specific code for this difference between OE 7.0 and odoo 8.0 implemented?
In openerp 7.0, server-> openerp-> modules-> module. py's addonsimporthook class has the following method:
Def find_module (self, module_name, package_path ):
Module_parts = module_name.split ('.')
If Len (module_parts) = 3 and module_name.startswith ('openerp. Addons .'):
Return self # We act as a loader too.
# Todo list of loadable modules can be cached instead of always
# Calling get_module_path ().
If Len (module_parts) = 1 and \
Get_module_path (module_parts [0],
Display_warning = false ):
Try:
# Check if the bare Module name clashes with another module.
F, path, descr = imp. find_module (module_parts [0])
_ Logger. Warning ("""
Ambiguous import: The openerp module '% s' is shadowed by another
Module (available at % s ).
To import it, use 'import openerp. Addons. <module>. '. "" % (module_name, PATH ))
Return
Failed t importerror, E:
# Using 'import <module_name> 'instead
# 'Import openerp. Addons. <module_name> 'is uugly but not harmful
# And kept for backward compatibility.
Return self # We act as a loader too.
In 8.0, this method is as follows:
Def find_module (self, module_name, package_path ):
Module_parts = module_name.split ('.')
If Len (module_parts) = 3 and module_name.startswith ('openerp. Addons .'):
Return self # We act as a loader too.
Obviously, 8.0 is less marked with yellow than 7.0. What is the use of the yellow part? It is compatible with the import <module> method. This type of import is not supported in 8.0.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service