From 4c3d90e1d0f6c7feb2dfccaeb671fd146e743aac Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 5 Oct 2020 10:57:40 +0000 Subject: [PATCH] [FIX] web: export should ignore requests for xid on views 5c4544fb2943e63fc1e0f5ae1e7e250a5a2b2cf1 reordered some of the operations at the export toplevel, and in doing so moved the filtering of the xid out of the `fields` list *after* that fields list has been used to know what fields to export. Meaning the fields list isn't filtered anymore, and requesting the xid on a view would blow up due to a latter assertion checking against that. Fix the filter, although a better solution might be to strip out the field upstream (in the fields list provided to the export wizard) such that users wouldn't even attempt to perform this export. An other possibility (possibly combined with the previous) could be to only strip out the export of the xid based on the absence of an ``id`` field on the model, though that's somewhat risky: technically views have no reason to be stable so a "record" could disappear or move around without the ORM being aware, leading to dangling xids. Fixes #46674 closes odoo/odoo#62995 X-original-commit: adc25bcf67438675bc9b0d55975ce733d58b4fb5 Signed-off-by: Xavier Morel (xmo) --- addons/web/controllers/main.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index f1095773a6d..15f40f5f7d7 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1892,13 +1892,16 @@ class ExportFormat(object): model, fields, ids, domain, import_compat = \ operator.itemgetter('model', 'fields', 'ids', 'domain', 'import_compat')(params) + Model = request.env[model].with_context(**params.get('context', {})) + if not Model._is_an_ordinary_table(): + fields = [field for field in fields if field['name'] != 'id'] + field_names = [f['name'] for f in fields] if import_compat: columns_headers = field_names else: columns_headers = [val['label'].strip() for val in fields] - Model = request.env[model].with_context(**params.get('context', {})) groupby = params.get('groupby') if not import_compat and groupby: groupby_type = [Model._fields[x.split(':')[0]].type for x in groupby] @@ -1916,11 +1919,9 @@ class ExportFormat(object): Model = Model.with_context(import_compat=import_compat) records = Model.browse(ids) if ids else Model.search(domain, offset=0, limit=False, order=False) - if not Model._is_an_ordinary_table(): - fields = [field for field in fields if field['name'] != 'id'] - export_data = records.export_data(field_names).get('datas',[]) response_data = self.from_data(columns_headers, export_data) + return request.make_response(response_data, headers=[('Content-Disposition', content_disposition(self.filename(model))),