diff --git a/odoo/sql_db.py b/odoo/sql_db.py index ed5cf07884d..4618653efd5 100644 --- a/odoo/sql_db.py +++ b/odoo/sql_db.py @@ -413,10 +413,17 @@ class Cursor(object): def savepoint(self): """context manager entering in a new savepoint""" name = uuid.uuid1().hex + env = next((e for e in Environment.envs if e.cr is self), None) + if env is not None: + env['base'].flush() self.execute('SAVEPOINT "%s"' % name) try: yield + if env is not None: + env['base'].flush() except Exception: + if env is not None: + env.clear() self.execute('ROLLBACK TO SAVEPOINT "%s"' % name) raise else: