Ticket #1652 (new enhancement)

Opened 2 years ago

Widgets should not update the datamodel if the value is not changed by the user

Reported by: ogrisel Assigned to: fguillaume
Priority: P2 Milestone: CPS 3.5.0
Component: CPSSchemas Version: 3.4.0
Severity: normal Keywords: optimization
Cc:

Description

Currently the majority of widgets (except the File widget) systematically edit the datamodel in their validate method even if the value has not been modified by the user.

The consequence is that the field is marked "dirty" in the datamodel and the computeDependantFields of the fields is called each time.

The solution would be to rewrite most widgets to change the validate methods from:

        datamodel[self.fields[0]] = v

to something like:

        if datamodel[self.fields[0]] != v:
            datamodel[self.fields[0]] = v

Alternatively the test could get factorized at the DataModel? level by rewriting the setitemmethode to something like:

    def __setitem__(self, key, item):
        self.checkWriteAccess(key)
        if self.data[key] != item:
            self.data[key] = item
            self.dirty[key] = 1

But the datamodel has no typing information on what 'item' is and the python inequality test might not be appropriate in all the use cases.