diff options
| author | Christophe Simonis <chs@odoo.com> | 2014-11-17 17:31:12 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2014-11-17 17:31:12 +0100 |
| commit | d64fe8279b4a1d3083a87b7e5fb211ddbbae50ca (patch) | |
| tree | 207e10e9f6f69206862c6329a5dcd25be5d15f9b /openerp/api.py | |
| parent | b2563509ffd89fdadc1256cb8118d7106f36e2e3 (diff) | |
| parent | c92e70b929376ba742ea17187ec521cf706302e5 (diff) | |
[MERGE] forward port of branch 8.0 up to c92e70b
Diffstat (limited to 'openerp/api.py')
| -rw-r--r-- | openerp/api.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/openerp/api.py b/openerp/api.py index da9e62f1549..94ed98c1265 100644 --- a/openerp/api.py +++ b/openerp/api.py @@ -815,6 +815,24 @@ class Environment(object): env.computed.clear() env.dirty.clear() + def clear(self): + """ Clear all record caches, and discard all fields to recompute. + This may be useful when recovering from a failed ORM operation. + """ + self.invalidate_all() + self.all.todo.clear() + + @contextmanager + def clear_upon_failure(self): + """ Context manager that clears the environments (caches and fields to + recompute) upon exception. + """ + try: + yield + except Exception: + self.clear() + raise + def field_todo(self, field): """ Check whether `field` must be recomputed, and returns a recordset with all records to recompute for `field`. |
