[FIX] web: export should ignore requests for xid on views
5c4544fb29 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) <xmo@odoo.com>
This commit is contained in:
@@ -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))),
|
||||
|
||||
Reference in New Issue
Block a user