diff options
| author | Samus CTO <cto@openerp.com> | 2014-08-25 20:41:51 +0200 |
|---|---|---|
| committer | Cécile Tonglet <cecile.tonglet@gmail.com> | 2014-08-25 14:38:20 +0200 |
| commit | aad19c73600a5f6ccb4b5481ead0309032eec6b6 (patch) | |
| tree | 1ddeaacd2fd55afdea5c69d387f4ef11bf8d19b1 | |
| parent | 8b4c7d76553c0a4d04b0e820cf288e9ea08c9538 (diff) | |
[FIX] model: prevent exporting column ID of non ordinary tables
This makes no sense and can generate errors if you try to purge
ir.model.data of not existing records.
| -rw-r--r-- | openerp/models.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/openerp/models.py b/openerp/models.py index fdc65e32118..bfc25b0f275 100644 --- a/openerp/models.py +++ b/openerp/models.py @@ -65,7 +65,7 @@ from .api import Environment from .exceptions import except_orm, AccessError, MissingError, ValidationError from .osv import fields from .osv.query import Query -from .tools import lazy_property +from .tools import lazy_property, ormcache from .tools.config import config from .tools.misc import CountingStream, DEFAULT_SERVER_DATETIME_FORMAT, DEFAULT_SERVER_DATE_FORMAT from .tools.safe_eval import safe_eval as eval @@ -836,8 +836,23 @@ class BaseModel(object): # prepare ormcache, which must be shared by all instances of the model cls._ormcache = {} + @api.model + @ormcache() + def _is_an_ordinary_table(self): + self.env.cr.execute("""\ + SELECT 1 + FROM pg_class + WHERE relname = %s + AND relkind = %s""", [self._table, 'r']) + return bool(self.env.cr.fetchone()) + def __export_xml_id(self): """ Return a valid xml_id for the record `self`. """ + if not self._is_an_ordinary_table(): + raise Exception( + "You can not export the column ID of model %s, because the " + "table %s is not an ordinary table." + % (self._name, self._table)) ir_model_data = self.sudo().env['ir.model.data'] data = ir_model_data.search([('model', '=', self._name), ('res_id', '=', self.id)]) if data: |
