[FIX] web: disable {bin_size: true} on binary fields

Revision on 41fe7f9d11

This commit intended to reduce the network load when reading records with
binary fields. This was made possible by enforcing the contextual key
`bin_size` to be set for records with binary fields.

However, it is causing some issues (see #22222, #22231) which are:
    - write with bin_size:true generates a traceback
    - read/search_read with bin_size:true breaks some images
      on some views (e.g. base.view_partner_form)

Since the problems outweight the gain of these changes, we revert them.
This commit is contained in:
Alexandre Kühn
2018-01-15 10:03:14 +01:00
parent 2a244e3e66
commit 2a5488619d
6 changed files with 7 additions and 15 deletions
@@ -1080,7 +1080,6 @@ var AbstractFieldBinary = AbstractField.extend({
},
'click .o_clear_file_button': 'on_clear',
}),
context: { bin_size: true },
init: function (parent, name, record) {
this._super.apply(this, arguments);
this.fields = record.fields;
@@ -387,10 +387,6 @@ return core.Class.extend({
attrs.fieldDependencies = attrs.Widget.prototype.fieldDependencies;
}
if (attrs.Widget.prototype.context) {
attrs.context = attrs.Widget.prototype.context;
}
return attrs;
},
/**
@@ -1854,7 +1854,7 @@ var BasicModel = AbstractModel.extend({
model: record.model,
method: 'read',
args: [[record.res_id], fieldNames],
context: record.getContext(),
context: _.extend({}, record.getContext(), {bin_size: true}),
})
.then(function (result) {
if (result.length === 0) {
@@ -3094,13 +3094,6 @@ var BasicModel = AbstractModel.extend({
// datapoint context is extended by fields widgets
var context = _.extend({}, params.context);
if (params.fieldsInfo && params.viewType) {
_.each(params.fieldsInfo[params.viewType], function (field) {
if (field.context) {
_.extend(context, field.context);
}
});
}
var dataPoint = {
_cache: type === 'list' ? {} : undefined,
@@ -6916,6 +6916,7 @@ QUnit.module('relational_fields', {
if (args.method === 'read' && args.model === 'partner') {
assert.deepEqual(args.kwargs.context, {
active_field: 2,
bin_size: true,
someKey: 'some value',
}, "sent context should be correct");
}
@@ -9250,7 +9251,7 @@ QUnit.module('relational_fields', {
'</tree>',
mockRPC: function (route, args) {
if (args.method === 'read' && args.model === 'partner_type') {
assert.deepEqual(args.kwargs.context, {take: 'five'},
assert.deepEqual(args.kwargs.context.take, 'five',
'The context should be passed to the RPC');
}
return this._super.apply(this, arguments);
@@ -74,6 +74,7 @@ QUnit.module('Views', {
mockRPC: function (route, args) {
assert.deepEqual(args.kwargs.context, {
active_field: 2,
bin_size: true,
someKey: 'some value',
}, "should have sent the correct context");
return this._super.apply(this, arguments);
+3 -1
View File
@@ -199,7 +199,7 @@ QUnit.module('Views', {
});
QUnit.test('only necessary fields are fetched with correct context', function (assert) {
assert.expect(1);
assert.expect(2);
var form = createView({
View: FormView,
@@ -214,6 +214,8 @@ QUnit.module('Views', {
// field, not sure why. Maybe this test should be modified.
assert.deepEqual(args.args[1], ["foo", "display_name"],
"should only fetch requested fields");
assert.deepEqual(args.kwargs.context, {bin_size: true},
"bin_size should always be in the context");
return this._super(route, args);
}
});