From f7e77afa19f72973c67aefb4cc43ee205dcae2a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 16 Aug 2012 14:57:00 +0200 Subject: [PATCH] Don't use Screen.save_current in button_clicked Screen.save_current force the reload of the record before the call to the Button RPC. So this could generate a race condition between the button call and the reload of the record. issue2739 review460001 (transplanted from dade8f50910b320f00618418a409f22f169b147a) --- tryton/gui/window/view_form/view/form.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tryton/gui/window/view_form/view/form.py b/tryton/gui/window/view_form/view/form.py index af75da275d..887c7af20d 100644 --- a/tryton/gui/window/view_form/view/form.py +++ b/tryton/gui/window/view_form/view/form.py @@ -166,10 +166,12 @@ class ViewForm(ParserView): focus_widget.grab_focus() def button_clicked(self, widget): - record_id = self.screen.save_current() record = self.screen.current_record attrs = widget.attrs - if record_id: + fields = self.get_fields() + if record.validate(fields): + # Don't reload as it will be done after the RPC call + record.save(force_reload=False) if not attrs.get('confirm', False) or \ common.sur(attrs['confirm']): button_type = attrs.get('type', 'object') @@ -177,7 +179,7 @@ class ViewForm(ParserView): if button_type == 'object': try: RPCExecute('model', self.screen.model_name, - attrs['name'], [record_id], context=context) + attrs['name'], [record.id], context=context) except RPCException: pass elif button_type == 'action': @@ -191,8 +193,8 @@ class ViewForm(ParserView): if action_id: Action.execute(action_id, { 'model': self.screen.model_name, - 'id': record_id, - 'ids': [record_id], + 'id': record.id, + 'ids': [record.id], }, context=context) else: raise Exception('Unallowed button type')