From 9ae4f0e80c4e6c03370d1e9da6097b141ac7ff33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 22 Jan 2023 01:41:52 +0100 Subject: [PATCH] Copy original state of wizard to avoid side effect Closes #4948 --- trytond/trytond/wizard/wizard.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/trytond/trytond/wizard/wizard.py b/trytond/trytond/wizard/wizard.py index cf82f89a6e..457d3ae7e2 100644 --- a/trytond/trytond/wizard/wizard.py +++ b/trytond/trytond/wizard/wizard.py @@ -214,8 +214,18 @@ class Wizard(URLMixin, PoolBase): # Copy states for attr in dir(cls): - if isinstance(getattr(cls, attr), State): - setattr(cls, attr, copy.deepcopy(getattr(cls, attr))) + if not isinstance(getattr(cls, attr), State): + continue + state_name = attr + state = getattr(cls, state_name) + # Copy the original state definition to prevent side-effect with + # the mutable attributes + for parent_cls in cls.__mro__: + parent_state = getattr(parent_cls, state_name, None) + if isinstance(parent_state, State): + state = parent_state + state = copy.deepcopy(state) + setattr(cls, attr, state) @classmethod def __post_setup__(cls):