Skip to content

Commit

Permalink
restore short circuit logic for conditional questions
Browse files Browse the repository at this point in the history
otherwise the list of questions that need to be answered errors out
  • Loading branch information
samuelhwilliams committed Feb 28, 2025
1 parent 57f0178 commit 926d6fc
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions proto/form_runner/form_route_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
ProtoDataCollectionQuestionCondition,
)
from proto.form_runner.expressions import build_context_evaluator
from proto.form_runner.helpers import get_answer_value_for_question_from_section_data


def get_visible_questions_for_section_instance(
Expand Down Expand Up @@ -41,6 +42,18 @@ def get_visible_questions_for_section_instance(
def evaluate_condition(
all_section_data: list[ProtoDataCollectionInstanceSectionData], condition: ProtoDataCollectionQuestionCondition
) -> bool:
if condition.depends_on_question:
section_data = next(
(sd for sd in all_section_data if sd.section_id == condition.depends_on_question.section_id), None
)
if not section_data: # If that section hasn't yet been completed
return False

depends_on_answer_text = get_answer_value_for_question_from_section_data(
section_data=section_data, question=condition.depends_on_question
)
if depends_on_answer_text is None:
return False
context_evaluator = build_context_evaluator(this_collection=all_section_data[0].instance, answer=None)
return bool(context_evaluator(condition.expression))

Expand Down

0 comments on commit 926d6fc

Please sign in to comment.