[gen] Stop caching methods used as default values for gen field: it can lead to headaches.
This commit is contained in:
parent
d9a89f7ad5
commit
30dbcb7dc7
2 changed files with 9 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue