Ticket #1652 (new enhancement)

Opened 13 years ago

Last modified 9 years ago

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

Reported by: ogrisel Owned by: fguillaume
Priority: P2 Milestone: CPS 3.5.7
Component: CPSSchemas Version: 3.4.0
Severity: normal Keywords: optimization


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):
        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.

Change History

comment:1 Changed 10 years ago by gracinet

  • Milestone changed from CPS 3.5.0 to CPS 3.5.1

I would go the datamodel way, using a new method exposed by the field itself. Note that nowadays, the dirty markers are really used to avoid unnecessary writes.

comment:2 Changed 9 years ago by gracinet

  • Milestone changed from CPS 3.5.1 to CPS 3.5.2

We can wait

Note: See TracTickets for help on using tickets.