[FIX] migrate_databases: convert exception before raising it to client

[IMP] the verification of the presence of the description and the validation 
	  of the quality certificate is done only at instanciation of the module

bzr revid: christophe@tinyerp.com-20090107155345-gb86zqkrulonb7sg
This commit is contained in:
Christophe Simonis 2009-01-07 16:53:45 +01:00
parent c56395453a
commit 6c360b6d59
3 changed files with 33 additions and 44 deletions

View File

@ -513,6 +513,8 @@ def load_module_graph(cr, graph, status=None, check_access_rules=True, **kwargs)
migrations = MigrationManager(cr, graph)
check_rules = False
modobj = None
for package in graph:
status['progress'] = (float(statusi)+0.1)/len(graph)
m = package.name
@ -524,6 +526,12 @@ def load_module_graph(cr, graph, status=None, check_access_rules=True, **kwargs)
logger.notifyChannel('init', netsvc.LOG_INFO, 'module %s loading objects' % m)
modules = pool.instanciate(m, cr)
if modobj is None:
modobj = pool.get('ir.module.module')
if modobj:
modobj.check(cr, 1, [mid])
idref = {}
status['progress'] = (float(statusi)+0.4)/len(graph)
if hasattr(package, 'init') or hasattr(package, 'update') or package.state in ('to install', 'to upgrade'):
@ -566,7 +574,6 @@ def load_module_graph(cr, graph, status=None, check_access_rules=True, **kwargs)
#cr.execute("update ir_module_module set state='installed', latest_version=%s where id=%s", (ver, mid,))
# Set new modules and dependencies
modobj = pool.get('ir.module.module')
modobj.write(cr, 1, [mid], {'state':'installed', 'latest_version':ver})
cr.commit()
@ -584,7 +591,6 @@ def load_module_graph(cr, graph, status=None, check_access_rules=True, **kwargs)
logger.notifyChannel('init', netsvc.LOG_WARNING, 'object %s (%s) has no access rules!' % (model,name))
pool = pooler.get_pool(cr.dbname)
cr.execute('select model from ir_model where state=%s', ('manual',))
for model in cr.dictfetchall():
pool.get('ir.model').instanciate(cr, 1, model['model'], {})

View File

@ -191,27 +191,6 @@ class module(osv.osv):
('certificate_uniq', 'unique (certificate)', 'The certificate ID of the module must be unique !')
]
def _check_certificate(self, cr, uid, ids):
if not ids:
return True
logger = netsvc.Logger()
for mod in self.browse(cr, uid, ids):
if not mod.certificate:
logger.notifyChannel('', netsvc.LOG_WARNING, 'module %s: no quality certificate' % mod.name)
else:
try:
val = long(mod.certificate) % 97 == 29
if not val:
raise Exception('Invalid Certificate')
except Exception, ex:
return False
return True
_constraints = [
(_check_certificate, "Your certificate is wrong !", ['certificate']),
]
def unlink(self, cr, uid, ids, context=None):
if not ids:
return True
@ -489,28 +468,21 @@ class module(osv.osv):
if os.path.exists(f):
logger.notifyChannel("init", netsvc.LOG_INFO, 'module %s: loading translation file for language %s' % (mod.name, lang))
tools.trans_load(cr.dbname, f, lang, verbose=False)
def write(self, cr, uid, ids, vals, context=None):
# Override the write method because we want to show a warning when the description field is empty !
if isinstance( ids, (long, int) ):
ids = [ids]
if 'description' in vals and not vals['description']:
logger = netsvc.Logger()
for mod in self.browse(cr, uid, ids):
logger.notifyChannel("init", netsvc.LOG_WARNING, 'module %s: description is empty !' % (mod.name))
def check(self, cr, uid, ids, context=None):
logger = netsvc.Logger()
for mod in self.browse(cr, uid, ids, context=context):
if not mod.description:
logger.notifyChannel("init", netsvc.LOG_WARNING, 'module %s: description is empty !' % (mod.name,))
return super(module, self).write(cr, uid, ids, vals, context=context)
def create(self, cr, uid, vals, context=None):
# Override the create method because we want to show a warning when the description field is empty !
module_id = super(module, self).create(cr, uid, vals, context=context)
if 'description' in vals and not vals['description']:
logger = netsvc.Logger()
for mod in self.browse(cr, uid, [module_id]):
logger.notifyChannel("init", netsvc.LOG_WARNING, 'module %s: description is empty !' % (mod.name))
return module_id
if not mod.certificate:
logger.notifyChannel('init', netsvc.LOG_WARNING, 'module %s: no quality certificate' % (mod.name,))
else:
val = long(mod.certificate) % 97 == 29
if not val:
logger.notifyChannel('init', netsvc.LOG_CRITICAL, 'module %s: invalid quality certificate: %s' % (mod.name, mod.certificate))
raise osv.except_osv(_('Error'), _('Module %s: Invalid Quality Certificate') % (mod.name,))
module()

View File

@ -277,6 +277,10 @@ class db(netsvc.Service):
return release.version
def migrate_databases(self, password, databases):
from osv.orm import except_orm
from osv.osv import except_osv
security.check_super(password)
l = netsvc.Logger()
for db in databases:
@ -284,8 +288,15 @@ class db(netsvc.Service):
l.notifyChannel('migration', netsvc.LOG_INFO, 'migrate database %s' % (db,))
tools.config['update']['base'] = True
pooler.restart_pool(db, force_demo=False, update_module=True)
except except_orm, inst:
self.abortResponse(1, inst.name, 'warning', inst.value)
except except_osv, inst:
self.abortResponse(1, inst.name, inst.exc_type, inst.value)
except Exception, e:
tools.debug(e)
import traceback
tb_s = reduce(lambda x, y: x+y, traceback.format_exception( sys.exc_type, sys.exc_value, sys.exc_traceback))
logger = Logger()
logger.notifyChannel('web-services', LOG_ERROR, tb_s)
raise
return True
db()