From 0c51a98f620fa1584c78903b117243bf1c13ddb0 Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Thu, 5 Jun 2014 16:37:15 -0400 Subject: [PATCH] Make code more robust to bad input (for case where DB was populated with string None) --- common/lib/xmodule/xmodule/seq_module.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/common/lib/xmodule/xmodule/seq_module.py b/common/lib/xmodule/xmodule/seq_module.py index 9afc602985..c872d62a46 100644 --- a/common/lib/xmodule/xmodule/seq_module.py +++ b/common/lib/xmodule/xmodule/seq_module.py @@ -1,5 +1,6 @@ import json import logging +import warnings from lxml import etree @@ -58,9 +59,18 @@ class SequenceModule(SequenceFields, XModule): def __init__(self, *args, **kwargs): super(SequenceModule, self).__init__(*args, **kwargs) - # if position is specified in system, then use that instead - if getattr(self.system, 'position', None) is not None: - self.position = int(self.system.position) + # If position is specified in system, then use that instead + # This code was made robust to avoid issues like LMS-2799 in + # Jira. We do not know whether this issue is still present, + # but regardless, we'd like to follow: + # http://en.wikipedia.org/wiki/Robustness_principle + + position = getattr(self.system, 'position', None) + if position is not None: + try: + self.position = int(self.system.position) + except (ValueError, TypeError): + warnings.warn("Sequential position is an invalid type.", RuntimeWarning) def get_progress(self): ''' Return the total progress, adding total done and total available.