Skip to content

Commit

Permalink
fix: handle deleted questions (#328)
Browse files Browse the repository at this point in the history
Step builder was raising `ValueError` if a question was deleted by the course author.
  • Loading branch information
mudassir-hafeez committed Apr 22, 2021
1 parent cb4125e commit d5755a3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
15 changes: 9 additions & 6 deletions problem_builder/mentoring.py
Expand Up @@ -890,12 +890,15 @@ def answer_mapper(self, answer_status):
for step in steps:
for answer in step.student_results:
if answer[1]['status'] == answer_status:
answer_map.append({
'id': answer[0],
'details': answer[1],
'step': step.step_number,
'number': self.get_question_number(answer[0]),
})
try:
answer_map.append({
'id': answer[0],
'details': answer[1],
'step': step.step_number,
'number': self.get_question_number(answer[0]),
})
except ValueError:
pass # The question has been deleted since the student answered it.
return answer_map

@property
Expand Down
18 changes: 15 additions & 3 deletions problem_builder/platform_dependencies.py
Expand Up @@ -29,10 +29,24 @@

# pylint: disable=unused-import

# TODO: It might make sense to handle imports separately. This part just
# separates the `StudentModule` import from others to avoid conflicting
# with `studentmodule` models in Juniper. Without this, a `RuntimeError`
# is raised, as it causes other modules to be imported with a full import
# path, which is not supported in Juniper.
try:
from courseware.models import StudentModule
except Exception:
try:
from lms.djangoapps.courseware.models import StudentModule
except ImportError:
# If we are not running within edx-platform
# (e.g., we are running problem-builder unit tests).
StudentModule = None

try:
# Koa and earlier: use shortened import path.
# This will raise a warning in Koa, but that's OK.
from courseware.models import StudentModule
from static_replace import replace_static_urls
from student.models import AnonymousUserId
from xblock_django.models import XBlockConfiguration
Expand All @@ -42,14 +56,12 @@
# of the former, and only exists on edx-platform master between Koa and Lilac).
try:
# Post-Koa: we must use the full import path.
from lms.djangoapps.courseware.models import StudentModule
from common.djangoapps.static_replace import replace_static_urls
from common.djangoapps.student.models import AnonymousUserId
from common.djangoapps.xblock_django.models import XBlockConfiguration
except ImportError:
# If we get here, we are not running within edx-platform
# (e.g., we are running problem-builder unit tests).
StudentModule = None
replace_static_urls = None
AnonymousUserId = None
XBlockConfiguration = None
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -28,7 +28,7 @@

# Constants #########################################################

VERSION = '4.1.12'
VERSION = '4.1.13'

# Functions #########################################################

Expand Down

0 comments on commit d5755a3

Please sign in to comment.