OCA / OpenUpgrade

Open source upgrade path for Odoo/OpenERP
https://oca.github.io/OpenUpgrade/
GNU Affero General Public License v3.0
734 stars 695 forks source link

[11.0] How to remove old data after migration #1758

Closed GabbasovDinar closed 5 years ago

GabbasovDinar commented 5 years ago

I migrated a database from 7.0 to 11.0 (using intermediate migrations 8.0-10.0). Then, I used the https://github.com/OCA/server-tools/tree/11.0/database_cleanup module and cleared the data, but in some cases, errors occur because old data is used. f.e.

  File "/home/diga/docker/odoo-11.0/odoo/odoo/fields.py", line 1001, in _compute_value
    getattr(records, self.compute)()
  File "/home/diga/docker/odoo-11.0/odoo/odoo/addons/base/ir/ir_actions.py", line 729, in _compute_params
    record.params = record_bin.params_store and safe_eval(record_bin.params_store, {'uid': self._uid})
  File "/home/diga/docker/odoo-11.0/odoo/odoo/tools/safe_eval.py", line 352, in safe_eval
    c = test_expr(expr, _SAFE_OPCODES, mode=mode)
  File "/home/diga/docker/odoo-11.0/odoo/odoo/tools/safe_eval.py", line 211, in test_expr
    code_obj = compile(expr, "", mode)
  File "<string>", line 1
    {'header_description': u'General announces for all employees.', 'compose_placeholder': 'Send a message to the group', 'search_view_id': 188, 'context': {'default_model': 'mail.group', 'default_res_id': 1L}, 'res_model': 'mail.message', 'thread_level': 1, 'domain': [('model', '=', 'mail.group'), ('res_id', '=', 1L)], 'view_mailbox': True}
                                                                                                                                                                                                               ^
SyntaxError: invalid syntax

We don't have the mail.group model in Odoo 11.0 (I have the error when I click to Settings > Technical > User Interface > Menu Items)

The second error:

Invoicing > Configuration > Analytic Acconting > Analytic Accounts

  File "/home/diga/docker/odoo-11.0/odoo/odoo/api.py", line 672, in call_kw_model
    result = method(recs, *args, **kwargs)
  File "/home/diga/docker/odoo-11.0/odoo/odoo/models.py", line 1296, in load_views
    for [v_id, v_type] in views
  File "/home/diga/docker/odoo-11.0/odoo/odoo/models.py", line 1296, in <dictcomp>
    for [v_id, v_type] in views
  File "/home/diga/docker/odoo-11.0/odoo/addons/mail/models/mail_thread.py", line 374, in fields_view_get
    res = super(MailThread, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
  File "/home/diga/docker/odoo-11.0/odoo/odoo/models.py", line 1388, in fields_view_get
    bindings = self.env['ir.actions.actions'].get_bindings(self._name)
  File "</usr/local/lib/python3.5/dist-packages/decorator.py:decorator-gen-27>", line 2, in get_bindings
  File "/home/diga/docker/odoo-11.0/odoo/odoo/tools/cache.py", line 89, in lookup
    value = d[key] = self.method(*args, **kwargs)
  File "/home/diga/docker/odoo-11.0/odoo/odoo/addons/base/ir/ir_actions.py", line 115, in get_bindings
    action = self.env[action_model].browse(action_id)
  File "/home/diga/docker/odoo-11.0/odoo/odoo/api.py", line 761, in __getitem__
    return self.registry[model_name]._browse((), self)
  File "/home/diga/docker/odoo-11.0/odoo/odoo/modules/registry.py", line 179, in __getitem__
    return self.models[model_name]
KeyError: 'ir.actions.wizard'

How can I fix it? Thanks P.S.-u alldidn't help

pedrobaeza commented 5 years ago

For that cases, you have to fix manually the problem. It seems a specific context was put on that action, or maybe some custom modules that mangle standard records. But this doesn't seem something generic to be fixed on OpenUpgrade itself.

GabbasovDinar commented 5 years ago

The error in the Analytic Accounts is related to the execution of the function: def get_bindings(self, model_name):

The function makes a request to the database:

cr = self.env.cr
        query = """ SELECT a.id, a.type, a.binding_type
                    FROM ir_actions a, ir_model m
                    WHERE a.binding_model_id=m.id AND m.model=%s
                    ORDER BY a.id """
        cr.execute(query, [model_name])

and cr.fetchall() there are two results:

action_model=ir.actions.act_window action_id=437 binding_type=action_form_only
action_model=ir.actions.wizard action_id=629 binding_type=action

The second result is incorrect How can I remove old data from db?

GabbasovDinar commented 5 years ago

The issue is solved if I use such request to the database.
DELETE FROM ir_actions WHERE id=629;

pedrobaeza commented 5 years ago

What is the XML-ID of that action? Can it be mangled by any extra module that changes any of the fields? In any case, this kind of operations is expected DB per DB due to a lot of possible interactions.

yelizariev commented 5 years ago

The issue is solved if I use such request to the database. DELETE FROM ir_actions WHERE id=629;

You might need to delete xml-id (record in ir.model.data) too to keep db clean

pedrobaeza commented 5 years ago

You might need to delete xml-id (record in ir.model.data) too to keep db clean

If I don't remember bad, database_cleanup module does this in an automated way for all dangling XML-IDs entries.

pedrobaeza commented 5 years ago

Closing as no news.