From 30dbcb7dc7db291323c40e851525b4d2de10d1ad Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Tue, 20 Jan 2015 14:02:57 +0100 Subject: [PATCH] [gen] Stop caching methods used as default values for gen field: it can lead to headaches. --- fields/__init__.py | 9 ++++++++- gen/ui/appy.css | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/fields/__init__.py b/fields/__init__.py index 9beccbb..0d7b27d 100644 --- a/fields/__init__.py +++ b/fields/__init__.py @@ -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 diff --git a/gen/ui/appy.css b/gen/ui/appy.css index f0d8bf0..eabb34d 100644 --- a/gen/ui/appy.css +++ b/gen/ui/appy.css @@ -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 }