Skip to content

Commit

Permalink
bug: [#4579] Ensure triggerFromStep uses the correct current_step
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stevenbal committed Dec 24, 2024
1 parent b837307 commit 51886a3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/openforms/submissions/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
6 changes: 5 additions & 1 deletion src/openforms/submissions/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 4 additions & 2 deletions src/openforms/submissions/form_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 51886a3

Please sign in to comment.