Browse Source

Merge pull request #1248 from acsone/10.0-module_auto_update-assert-sbi

[10.0] module auto update: add post condition check
pull/1250/head
Pedro M. Baeza 7 years ago
committed by GitHub
parent
commit
3149cb6a68
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      module_auto_update/__manifest__.py
  2. 25
      module_auto_update/models/module.py

2
module_auto_update/__manifest__.py

@ -5,7 +5,7 @@
{ {
'name': 'Module Auto Update', 'name': 'Module Auto Update',
'summary': 'Automatically update Odoo modules', 'summary': 'Automatically update Odoo modules',
'version': '10.0.2.0.1',
'version': '10.0.2.0.2',
'category': 'Extra Tools', 'category': 'Extra Tools',
'website': 'https://github.com/OCA/server-tools', 'website': 'https://github.com/OCA/server-tools',
'author': 'LasLabs, ' 'author': 'LasLabs, '

25
module_auto_update/models/module.py

@ -22,10 +22,30 @@ DEFAULT_EXCLUDE_PATTERNS = \
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
class FailedUpgradeError(exceptions.UserError):
pass
class IncompleteUpgradeError(exceptions.UserError): class IncompleteUpgradeError(exceptions.UserError):
pass pass
def ensure_module_state(env, modules, state):
# read module states, bypassing any Odoo cache
env.cr.execute(
"SELECT name FROM ir_module_module "
"WHERE id IN %s AND state != %s",
(tuple(modules.ids), state),
)
names = [r[0] for r in env.cr.fetchall()]
if names:
raise FailedUpgradeError(
"The following modules should be in state '%s' "
"at this stage: %s. Bailing out for safety." %
(state, ','.join(names), ),
)
class Module(models.Model): class Module(models.Model):
_inherit = 'ir.module.module' _inherit = 'ir.module.module'
@ -128,6 +148,11 @@ class Module(models.Model):
','.join(changed_modules.mapped('name'))) ','.join(changed_modules.mapped('name')))
changed_modules.button_upgrade() changed_modules.button_upgrade()
self.env.cr.commit() # pylint: disable=invalid-commit self.env.cr.commit() # pylint: disable=invalid-commit
# in rare situations, button_upgrade may fail without
# exception, this would lead to corruption because
# no upgrade would be performed and save_installed_checksums
# would update cheksums for modules that have not been upgraded
ensure_module_state(self.env, changed_modules, 'to upgrade')
_logger.info("Upgrading...") _logger.info("Upgrading...")
self.env['base.module.upgrade'].upgrade_module() self.env['base.module.upgrade'].upgrade_module()

Loading…
Cancel
Save