In an interface for a form, why is my defaultFactory function being called in BrowserView?

I had a similar problem, it looks like the field never store a value so every time your view needs the value it call the defaultFactory.

This will be ok if you test for context in the factory

if context is None:
    return  some_value
return exchangeRate

This is because when you create an object applyChanges in z3c.form.form is called, here the value is updated only if the data is different from the stored value. In this case the data we want to save is the default value. To get the current field value it calls the defaultFactory. When this two values are compared they are equal so no value is saved.
It turned out that when applyChanges calls defaultFactory context is None.

2 Likes