relational custom fields incompatible with server update: AttributeError: 'NoneType' object has no attribute '_table'

Bug #493657 reported by Xavier Fernandez http://www.smile.fr
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
High
Unassigned

Bug Description

On server 5.0 (rev: 1902), create a new database with minimal profile, install addons product and delivery.
Add a custom m2o field 'x_test' on product.product pointing to delivery.carrier .

Restart the server with --update=product and you'll get this kind of stacktrace:
[2009-12-07 18:13:09,168] INFO:init:module product: creating or updating database tables
Traceback (most recent call last):
  File "./bin/openerp-server.py", line 111, in <module>
    pooler.get_db_and_pool(db, update_module=tools.config['init'] or tools.config['update'])
  File "/home/xafer/openerp/5.0/server-5.0/bin/pooler.py", line 40, in get_db_and_pool
    addons.load_modules(db, force_demo, status, update_module)
  File "/home/xafer/openerp/5.0/server-5.0/bin/addons/__init__.py", line 738, in load_modules
    r = load_module_graph(cr, graph, status, report=report)
  File "/home/xafer/openerp/5.0/server-5.0/bin/addons/__init__.py", line 581, in load_module_graph
    init_module_objects(cr, package.name, modules)
  File "/home/xafer/openerp/5.0/server-5.0/bin/addons/__init__.py", line 366, in init_module_objects
    result = obj._auto_init(cr, {'module': module_name})
  File "/home/xafer/openerp/5.0/server-5.0/bin/osv/orm.py", line 1915, in _auto_init
    ref = self.pool.get(f._obj)._table
AttributeError: 'NoneType' object has no attribute '_table'

As far as I understand, the 'x_test' custom field is loaded with the rest of the product.product fields before the delivery addon is actually loaded, making it point to a currently unknown 'delivery.carrier' object known in the stacktrace as 'NoneType'.

Related branches

Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :

Hello I confirm the bug; this is a critical one for the Magento connector, see this bug:
https://bugs.launchpad.net/magentoerpconnect/+bug/484843
And we also guess this would cause bugs especially in Odoo where customization is achieved rather by adding custom fields than writing your own modules.
So fix in 5.0.7 would be cool. meanwhile we understand if that should wait.

Changed in openobject-server:
status: New → Confirmed
importance: Undecided → High
milestone: none → 5.0.7
Revision history for this message
Xavier Fernandez http://www.smile.fr (xav-fernandez) wrote :

A quick fix for all custom fields not pointing to 'ir_actions' is included in the patch in attachment.

A better solution would be to load the custom fields only when all the modules and objects have been loaded.

Revision history for this message
Xavier Fernandez http://www.smile.fr (xav-fernandez) wrote :

(The patch is only a poor fix for many2one custom field, so it can help out while waiting for a clever modification but it certainly is not the solution)

Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :

Hello,

a few more tests if that can helps:

If you change the custom field state to "base" instead of "manual" (using SQL), then just after you created the field, it's usable in your object. After that change, you can also restart you server with --update=module_with_model_where_custom_field_is_defined
It won't break into the error mentioned by Xavier in that case.

However, doing this change, once you updated the server, the field won't be found anymore in the object, views will break into errors because of that for instance. So this is not a possible workaround and may be knowing how it behaves for 'base' state custom fields helps you to find a fix.

Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :

Hello again,

so I agree with Xavier's analysis: currently, as soon as a module loads an object, it loads all its custom fields. So custom fields referencing an object loaded by a module that is not yet loaded (because not a dependence of the current module; can perfectly happen, see the delivery module example) will never get a chance do the DDL it attempts in the _auto_init method.

I don't see any clean way of doing it. As Xavier says, those fields should be loaded at the end eventually or, as a less optimal solution is to forget any DDL in _auto_init when encountering a field that depends on a model that can be found using self.pool.get(model_name).

Meanwhile, if you are stuck with this bug, I wrote an SQL workaround to manage your server upgrade manually here:
https://bugs.launchpad.net/magentoerpconnect/+bug/484843

Hope to see a clean solution still. Due to the complexity of the bug resolution, I'm descoping it from 5.0.7. That's still an important bug. With it, 50% of custom fields which is pimped as a super OpenERP feature will never pass any server update for the mere mortal users.

Changed in openobject-server:
milestone: 5.0.7 → none
summary: - Custom fields obstructing updates
+ relational custom fields incompatible with server update:
+ AttributeError: 'NoneType' object has no attribute '_table'
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Hello Xavier and Raphael,

I think,the CHECK of self.pool.get(Object) is quite fair.

As far as the creation of the custom field is concerned, when its created ;,it calls _auto_init() for that object. so the purpose of new field is served, Even the column is added too.
At this time, The object will be available in pool.
Example: By customization in GUI : in product.product; I am adding sale_order_id(many2one of Sale.order), When I press Save,it will add this column to product_product through _auto_init(). Work is Done! (self.pool dictionary will have sale.order)

Now, when I update the database and/or product module,POOL will not have the record of sale.order when its loading Product module. But But But, its a custom field, it does not need any update here at this point of time.So, its fine if we skip.

If someone argues that what if I have updated the custom field?Answer would be, If you update(EDIT) the custom field, we can call _auto_init() on write() if important field is updated.

Share your views please.

Thank you.

Changed in openobject-server:
status: Confirmed → In Progress
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Thank you for your patience and responses for this thread.

It has been fixed by revision 1963 <email address hidden>.

Changed in openobject-server:
status: In Progress → Fix Released
Revision history for this message
charton Jérémie (jcharton) wrote :

Hi.
I'm working under v6.1 (ubuntu & windows).
I still get the bug:
when I create a custom field under web interface, then later i decide to add it directly in the code :

Client Traceback (most recent call last):
  File "C:\Program Files (x86)\OpenERP 6.1-1\server\openerp\addons\web\common\http.py", line 180, in dispatch
  File "C:\Program Files (x86)\OpenERP 6.1-1\server\openerp\addons\web\controllers\main.py", line 466, in authenticate
  File "C:\Program Files (x86)\OpenERP 6.1-1\server\openerp\addons\web\common\session.py", line 73, in authenticate
  File "C:\Program Files (x86)\OpenERP 6.1-1\server\openerp\addons\web\common\openerplib\main.py", line 117, in proxy
  File "C:\Program Files (x86)\OpenERP 6.1-1\server\openerp\addons\web\common\http.py", line 611, in send

Server Traceback (most recent call last):
  File "C:\Program Files (x86)\OpenERP 6.1-1\server\openerp\addons\web\common\http.py", line 592, in send
  File "C:\Program Files (x86)\OpenERP 6.1-1\server\.\openerp\netsvc.py", line 360, in dispatch_rpc
  File "C:\Program Files (x86)\OpenERP 6.1-1\server\.\openerp\service\web_services.py", line 384, in dispatch
  File "C:\Program Files (x86)\OpenERP 6.1-1\server\.\openerp\service\web_services.py", line 395, in exp_authenticate
  File "C:\Program Files (x86)\OpenERP 6.1-1\server\.\openerp\pooler.py", line 50, in get_pool
  File "C:\Program Files (x86)\OpenERP 6.1-1\server\.\openerp\pooler.py", line 33, in get_db_and_pool
  File "C:\Program Files (x86)\OpenERP 6.1-1\server\.\openerp\modules\registry.py", line 138, in get
  File "C:\Program Files (x86)\OpenERP 6.1-1\server\.\openerp\modules\registry.py", line 160, in new
  File "C:\Program Files (x86)\OpenERP 6.1-1\server\.\openerp\modules\loading.py", line 334, in load_modules
  File "C:\Program Files (x86)\OpenERP 6.1-1\server\.\openerp\modules\loading.py", line 253, in load_marked_modules
  File "C:\Program Files (x86)\OpenERP 6.1-1\server\.\openerp\modules\loading.py", line 170, in load_module_graph
  File "C:\Program Files (x86)\OpenERP 6.1-1\server\.\openerp\modules\module.py", line 378, in init_module_models
  File "C:\Program Files (x86)\OpenERP 6.1-1\server\.\openerp\osv\orm.py", line 2935, in _auto_init
AttributeError: 'NoneType' object has no attribute '_table'

It's gonna be a critical issue for me!!!!
Thanks in advance.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Patches

Remote bug watches

Bug watches keep track of this bug in other bug trackers.