From 5bbd7ea0bae2c505c7a390f319ca36edc4fe26e6 Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Mon, 23 Dec 2024 15:03:05 +0100 Subject: [PATCH] :bug: [#4579] Ensure triggerFromStep uses the correct current_step previously the current step was inferred by looking at the last completed step and considering the step after that the current step. This does not work however if you complete a step and go back to the previous step, so instead we explicitly pass the current form step via the serializer context --- src/openforms/submissions/api/serializers.py | 6 +++++- src/openforms/submissions/api/viewsets.py | 6 +++++- src/openforms/submissions/form_logic.py | 6 ++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/openforms/submissions/api/serializers.py b/src/openforms/submissions/api/serializers.py index f40fc2be86..341532f99e 100644 --- a/src/openforms/submissions/api/serializers.py +++ b/src/openforms/submissions/api/serializers.py @@ -200,7 +200,11 @@ def create(self, validated_data): return super().create(validated_data) def to_representation(self, instance): - check_submission_logic(instance, unsaved_data=self.context.get("unsaved_data")) + check_submission_logic( + instance, + unsaved_data=self.context.get("unsaved_data"), + current_step=self.context.get("current_step"), + ) return super().to_representation(instance) diff --git a/src/openforms/submissions/api/viewsets.py b/src/openforms/submissions/api/viewsets.py index 05b738f0ff..784183f258 100644 --- a/src/openforms/submissions/api/viewsets.py +++ b/src/openforms/submissions/api/viewsets.py @@ -635,6 +635,10 @@ def logic_check(self, request, *args, **kwargs): submission_state_logic_serializer = SubmissionStateLogicSerializer( instance=SubmissionStateLogic(submission=submission, step=submission_step), - context={"request": request, "unsaved_data": data}, + context={ + "request": request, + "unsaved_data": data, + "current_step": submission_step, + }, ) return Response(submission_state_logic_serializer.data) diff --git a/src/openforms/submissions/form_logic.py b/src/openforms/submissions/form_logic.py index 8691dfc8d4..f48c999c9f 100644 --- a/src/openforms/submissions/form_logic.py +++ b/src/openforms/submissions/form_logic.py @@ -188,7 +188,9 @@ def evaluate_form_logic( def check_submission_logic( - submission: "Submission", unsaved_data: dict | None = None + submission: "Submission", + unsaved_data: dict | None = None, + current_step: "SubmissionStep | None" = None, ) -> None: if getattr(submission, "_form_logic_evaluated", False): return @@ -198,7 +200,7 @@ def check_submission_logic( if not submission_state.form_steps: return - rules = get_rules_to_evaluate(submission) + rules = get_rules_to_evaluate(submission, current_step) # load the data state and all variables submission_variables_state = submission.load_submission_value_variables_state()