From 9032562cbd6826fbde02448cc15d5b9fd755d203 Mon Sep 17 00:00:00 2001 From: Awais Jibran Date: Thu, 27 Feb 2020 10:55:18 +0500 Subject: [PATCH] Fix Error in find_question_label. --- common/lib/capa/capa/capa_problem.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/common/lib/capa/capa/capa_problem.py b/common/lib/capa/capa/capa_problem.py index b1753066ea..48ab9833b3 100644 --- a/common/lib/capa/capa/capa_problem.py +++ b/common/lib/capa/capa/capa_problem.py @@ -562,7 +562,12 @@ class LoncapaProblem(object): """ _ = get_gettext(self.capa_system.i18n) # Some questions define a prompt with this format: >>This is a prompt<< - prompt = self.problem_data[answer_id].get('label') + log_error = False + try: + prompt = self.problem_data[answer_id].get('label') + except KeyError: + log_error = True + prompt = self.problem_data.get(answer_id, {}).get('label') if prompt: question_text = prompt.striptags() @@ -607,6 +612,11 @@ class LoncapaProblem(object): question_nr = int(answer_id.split('_')[-2]) - 1 question_text = _("Question {0}").format(question_nr) + if log_error: + log.error( + 'KeyError: answer_id: %s, Problem data: %s, question_text: %s', + (answer_id, self.problem_data, question_text) + ) return question_text def find_answer_text(self, answer_id, current_answer):