Skip to content

Commit d5755a3

Browse files
fix: handle deleted questions (#328)
Step builder was raising `ValueError` if a question was deleted by the course author.
1 parent cb4125e commit d5755a3

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

problem_builder/mentoring.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -890,12 +890,15 @@ def answer_mapper(self, answer_status):
890890
for step in steps:
891891
for answer in step.student_results:
892892
if answer[1]['status'] == answer_status:
893-
answer_map.append({
894-
'id': answer[0],
895-
'details': answer[1],
896-
'step': step.step_number,
897-
'number': self.get_question_number(answer[0]),
898-
})
893+
try:
894+
answer_map.append({
895+
'id': answer[0],
896+
'details': answer[1],
897+
'step': step.step_number,
898+
'number': self.get_question_number(answer[0]),
899+
})
900+
except ValueError:
901+
pass # The question has been deleted since the student answered it.
899902
return answer_map
900903

901904
@property

problem_builder/platform_dependencies.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,24 @@
2929

3030
# pylint: disable=unused-import
3131

32+
# TODO: It might make sense to handle imports separately. This part just
33+
# separates the `StudentModule` import from others to avoid conflicting
34+
# with `studentmodule` models in Juniper. Without this, a `RuntimeError`
35+
# is raised, as it causes other modules to be imported with a full import
36+
# path, which is not supported in Juniper.
37+
try:
38+
from courseware.models import StudentModule
39+
except Exception:
40+
try:
41+
from lms.djangoapps.courseware.models import StudentModule
42+
except ImportError:
43+
# If we are not running within edx-platform
44+
# (e.g., we are running problem-builder unit tests).
45+
StudentModule = None
46+
3247
try:
3348
# Koa and earlier: use shortened import path.
3449
# This will raise a warning in Koa, but that's OK.
35-
from courseware.models import StudentModule
3650
from static_replace import replace_static_urls
3751
from student.models import AnonymousUserId
3852
from xblock_django.models import XBlockConfiguration
@@ -42,14 +56,12 @@
4256
# of the former, and only exists on edx-platform master between Koa and Lilac).
4357
try:
4458
# Post-Koa: we must use the full import path.
45-
from lms.djangoapps.courseware.models import StudentModule
4659
from common.djangoapps.static_replace import replace_static_urls
4760
from common.djangoapps.student.models import AnonymousUserId
4861
from common.djangoapps.xblock_django.models import XBlockConfiguration
4962
except ImportError:
5063
# If we get here, we are not running within edx-platform
5164
# (e.g., we are running problem-builder unit tests).
52-
StudentModule = None
5365
replace_static_urls = None
5466
AnonymousUserId = None
5567
XBlockConfiguration = None

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
# Constants #########################################################
3030

31-
VERSION = '4.1.12'
31+
VERSION = '4.1.13'
3232

3333
# Functions #########################################################
3434

0 commit comments

Comments
 (0)