[gen] Stop caching methods used as default values for gen field: it can lead to headaches.

This commit is contained in:
Gaetan Delannay 2015-01-20 14:02:57 +01:00
parent d9a89f7ad5
commit 30dbcb7dc7
2 changed files with 9 additions and 1 deletions

View file

@ -570,7 +570,14 @@ class Field:
# self.default, of self.default() if it is a method.
if callable(self.default):
try:
return self.callMethod(obj, self.default)
# Caching a default value can lead to problems. For example,
# the process of creating an object from another one, or
# from some data, sometimes consists in (a) creating an
# "empty" object, (b) initializing its values and
# (c) reindexing it. Default values are computed in (a),
# but it they depend on values set at (b), and are cached
# and indexed, (c) will get the wrong, cached value.
return self.callMethod(obj, self.default, cache=False)
except Exception, e:
# Already logged. Here I do not raise the exception,
# because it can be raised as the result of reindexing

View file

@ -94,6 +94,7 @@ input.buttonFixed { width:110px; padding: 0 0 0 10px }
.portletGroup { font-variant: small-caps; font-weight: bold; font-size: 110%;
margin: 0.1em 0 0.3em ; border-bottom: 1px dashed #c0c0c0 }
.portletSearch { font-size: 90%; font-style: italic }
.portletCurrent { font-weight: bold }
.inputSearch { height: 15px; width: 132px; margin: 3px 3px 2px 3px !important }
td.search { padding-top: 8px }
.content { padding: 9px; background-color: #fbfbfb }