Search code examples
odooodoo-8

In odoo where advanced-view-editor in saving files


I have made a mistake while customizing the default template in odoo. The error is located in the list of categories of the e-commerce module. After saving my change, Odoo reported an error on th UI and proposed to rollback. Since then, odoo website doesn't work at all.

Where can I find the modified files on the server to change discard my changes? Here is my log trace... which doesn't help much!

2016-04-25 19:41:13,773 1505 ERROR fa_prod werkzeug: Error on request:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 177, in run_wsgi
    execute(self.server.app)
  File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 165, in execute
    application_iter = app(environ, start_response)
  File "/opt/openerp/odoo/openerp/service/server.py", line 290, in app
    return self.app(e, s)
  File "/opt/openerp/odoo/openerp/service/wsgi_server.py", line 214, in application
    return werkzeug.contrib.fixers.ProxyFix(application_unproxied)(environ, start_response)
  File "/usr/lib/python2.7/dist-packages/werkzeug/contrib/fixers.py", line 144, in __call__
    return self.app(environ, start_response)
  File "/opt/openerp/odoo/openerp/service/wsgi_server.py", line 202, in application_unproxied
    result = handler(environ, start_response)
  File "/opt/openerp/odoo/openerp/http.py", line 1290, in __call__
    return self.dispatch(environ, start_response)
  File "/opt/openerp/odoo/openerp/http.py", line 1264, in __call__
    return self.app(environ, start_wrapped)
  File "/usr/lib/python2.7/dist-packages/werkzeug/wsgi.py", line 588, in __call__
    return self.app(environ, start_response)
  File "/opt/openerp/odoo/openerp/http.py", line 1428, in dispatch
    ir_http = request.registry['ir.http']
  File "/opt/openerp/odoo/openerp/http.py", line 346, in registry
    return openerp.modules.registry.RegistryManager.get(self.db) if self.db else None
  File "/opt/openerp/odoo/openerp/modules/registry.py", line 339, in get
    update_module)
  File "/opt/openerp/odoo/openerp/modules/registry.py", line 370, in new
    openerp.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/opt/openerp/odoo/openerp/modules/loading.py", line 351, in load_modules
    force, status, report, loaded_modules, update_module)
  File "/opt/openerp/odoo/openerp/modules/loading.py", line 255, in load_marked_modules
    loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
  File "/opt/openerp/odoo/openerp/modules/loading.py", line 157, in load_module_graph
    init_module_models(cr, package.name, models)
  File "/opt/openerp/odoo/openerp/modules/module.py", line 293, in init_module_models
    obj._auto_end(cr, {'module': module_name})
  File "/opt/openerp/odoo/openerp/api.py", line 250, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/openerp/odoo/openerp/models.py", line 2710, in _auto_end
    cr.execute('ALTER TABLE "%s" ADD FOREIGN KEY ("%s") REFERENCES "%s" ON DELETE %s' % (t, k, r, d))
  File "/opt/openerp/odoo/openerp/sql_db.py", line 158, in wrapper
    return f(self, *args, **kwargs)
  File "/opt/openerp/odoo/openerp/sql_db.py", line 234, in execute
    res = self._obj.execute(query, params)
ProgrammingError: there is no primary key for referenced table "res_users"

Solution

  • What happened is that Odoo corrupted the database while rolling back a template. Most of the tables had lost their primary keys.

    In order to set them up again, I have executed the following code on a working instance to get he list of primary keys:

    select tc.table_schema, tc.table_name, kc.column_name, kc.constraint_name
    from  
        information_schema.table_constraints tc,  
        information_schema.key_column_usage kc  
    where 
        tc.constraint_type = 'PRIMARY KEY' 
        and kc.table_name = tc.table_name and kc.table_schema = tc.table_schema
        and kc.constraint_name = tc.constraint_name
    order by 1, 2;
    

    Then I exported the list of tales from the corrupted database:

    select table_name from information_schema.tables;
    

    I matched this in excel and build a list of queries to be executed to get the primary keys again:

    ="ALTER TABLE "&B15&" ADD PRIMARY KEY ("&C15&");"`enter code here`
    

    Where B is the column with tables and C with primary key field name. This gives a lits of SQL queries like so:

    ALTER TABLE product_template ADD PRIMARY KEY (id);
    ALTER TABLE product_ul ADD PRIMARY KEY (id);
    ALTER TABLE product_uom ADD PRIMARY KEY (id);
    ALTER TABLE product_uom_categ ADD PRIMARY KEY (id);
    ...
    

    We can execute this on the DB directly. I restarted Odoo and voilà.