From bd1e9aa129c3f58f1888c2a6332bfb62c14a241b Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Mon, 18 May 2015 12:01:46 -0400 Subject: [PATCH] Record valid scopes when raising InvalidScopeError --- .../lib/xmodule/xmodule/modulestore/mongo/base.py | 15 ++++++++++++--- .../modulestore/split_mongo/split_mongo_kvs.py | 12 +++++++----- lms/djangoapps/courseware/model_data.py | 2 +- requirements/edx/github.txt | 2 +- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/mongo/base.py b/common/lib/xmodule/xmodule/modulestore/mongo/base.py index f005a7cded..c85c554e22 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo/base.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo/base.py @@ -119,7 +119,10 @@ class MongoKeyValueStore(InheritanceKeyValueStore): elif key.scope == Scope.content: return self._data[key.field_name] else: - raise InvalidScopeError(key) + raise InvalidScopeError( + key, + (Scope.children, Scope.parent, Scope.settings, Scope.content), + ) def set(self, key, value): if key.scope == Scope.children: @@ -129,7 +132,10 @@ class MongoKeyValueStore(InheritanceKeyValueStore): elif key.scope == Scope.content: self._data[key.field_name] = value else: - raise InvalidScopeError(key) + raise InvalidScopeError( + key, + (Scope.children, Scope.settings, Scope.content), + ) def delete(self, key): if key.scope == Scope.children: @@ -141,7 +147,10 @@ class MongoKeyValueStore(InheritanceKeyValueStore): if key.field_name in self._data: del self._data[key.field_name] else: - raise InvalidScopeError(key) + raise InvalidScopeError( + key, + (Scope.children, Scope.settings, Scope.content), + ) def has(self, key): if key.scope in (Scope.children, Scope.parent): diff --git a/common/lib/xmodule/xmodule/modulestore/split_mongo/split_mongo_kvs.py b/common/lib/xmodule/xmodule/modulestore/split_mongo/split_mongo_kvs.py index 2124732242..8720b7c3d9 100644 --- a/common/lib/xmodule/xmodule/modulestore/split_mongo/split_mongo_kvs.py +++ b/common/lib/xmodule/xmodule/modulestore/split_mongo/split_mongo_kvs.py @@ -18,6 +18,8 @@ class SplitMongoKVS(InheritanceKeyValueStore): known to the MongoModuleStore (data, children, and metadata) """ + VALID_SCOPES = (Scope.parent, Scope.children, Scope.settings, Scope.content) + @contract(parent="BlockUsageLocator | None") def __init__(self, definition, initial_values, default_values, parent, field_decorator=None): """ @@ -59,7 +61,7 @@ class SplitMongoKVS(InheritanceKeyValueStore): else: raise KeyError() else: - raise InvalidScopeError(key) + raise InvalidScopeError(key, self.VALID_SCOPES) if key.field_name in self._fields: field_value = self._fields[key.field_name] @@ -71,8 +73,8 @@ class SplitMongoKVS(InheritanceKeyValueStore): def set(self, key, value): # handle any special cases - if key.scope not in [Scope.children, Scope.settings, Scope.content]: - raise InvalidScopeError(key) + if key.scope not in self.VALID_SCOPES: + raise InvalidScopeError(key, self.VALID_SCOPES) if key.scope == Scope.content: self._load_definition() @@ -90,8 +92,8 @@ class SplitMongoKVS(InheritanceKeyValueStore): def delete(self, key): # handle any special cases - if key.scope not in [Scope.children, Scope.settings, Scope.content]: - raise InvalidScopeError(key) + if key.scope not in self.VALID_SCOPES: + raise InvalidScopeError(key, self.VALID_SCOPES) if key.scope == Scope.content: self._load_definition() diff --git a/lms/djangoapps/courseware/model_data.py b/lms/djangoapps/courseware/model_data.py index 5532e0ef89..7dfa1002b2 100644 --- a/lms/djangoapps/courseware/model_data.py +++ b/lms/djangoapps/courseware/model_data.py @@ -129,7 +129,7 @@ class DjangoKeyValueStore(KeyValueStore): def _raise_unless_scope_is_allowed(self, key): """Raise an InvalidScopeError if key.scope is not in self._allowed_scopes.""" if key.scope not in self._allowed_scopes: - raise InvalidScopeError(key) + raise InvalidScopeError(key, self._allowed_scopes) new_contract("DjangoKeyValueStore", DjangoKeyValueStore) diff --git a/requirements/edx/github.txt b/requirements/edx/github.txt index aa652261f2..5e6adfa953 100644 --- a/requirements/edx/github.txt +++ b/requirements/edx/github.txt @@ -29,7 +29,7 @@ git+https://github.com/pmitros/pyfs.git@96e1922348bfe6d99201b9512a9ed946c87b7e0b git+https://github.com/hmarr/django-debug-toolbar-mongo.git@b0686a76f1ce3532088c4aee6e76b9abe61cc808 # Our libraries: --e git+https://github.com/edx/XBlock.git@1934a2978cdd3e2414486c74b76e3040ff1fb138#egg=XBlock +-e git+https://github.com/cpennington/XBlock.git@e9c4d441d1eaf7c9f176b873fe23e24c1152dba6#egg=XBlock -e git+https://github.com/edx/codejail.git@6b17c33a89bef0ac510926b1d7fea2748b73aadd#egg=codejail -e git+https://github.com/edx/js-test-tool.git@v0.1.6#egg=js_test_tool -e git+https://github.com/edx/event-tracking.git@0.2.0#egg=event-tracking