Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
e972b230
Commit
e972b230
authored
Mar 04, 2014
by
Don Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Requesting an xmodule field in wrong app context raises exception rather than assertion
parent
563b713a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
5 deletions
+17
-5
common/lib/xmodule/xmodule/exceptions.py
+7
-0
common/lib/xmodule/xmodule/modulestore/mixed.py
+7
-4
common/lib/xmodule/xmodule/x_module.py
+3
-1
No files found.
common/lib/xmodule/xmodule/exceptions.py
View file @
e972b230
...
...
@@ -31,3 +31,10 @@ class SerializationError(Exception):
def
__init__
(
self
,
location
,
msg
):
super
(
SerializationError
,
self
)
.
__init__
(
msg
)
self
.
location
=
location
class
UndefinedContext
(
Exception
):
"""
Tried to access an xmodule field which needs a different context (runtime) to have a value.
"""
pass
common/lib/xmodule/xmodule/modulestore/mixed.py
View file @
e972b230
...
...
@@ -15,6 +15,7 @@ from xmodule.modulestore.exceptions import ItemNotFoundError, InvalidLocationErr
from
uuid
import
uuid4
from
xmodule.modulestore.mongo.base
import
MongoModuleStore
from
xmodule.modulestore.split_mongo.split
import
SplitMongoModuleStore
from
xmodule.exceptions
import
UndefinedContext
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -207,9 +208,10 @@ class MixedModuleStore(ModuleStoreWriteBase):
"""
Get the course_id from the block or from asking its store. Expensive.
"""
# HACK: check xmodule_runtime to avoid an assertion error
if
block
.
xmodule_runtime
is
not
None
and
block
.
course_id
is
not
None
:
try
:
return
block
.
course_id
except
UndefinedContext
:
pass
try
:
course
=
store
.
_get_course_for_item
(
block
.
scope_ids
.
usage_id
)
if
course
is
not
None
:
...
...
@@ -262,9 +264,10 @@ class MixedModuleStore(ModuleStoreWriteBase):
blocks
=
store
.
get_items
(
location
)
if
len
(
blocks
)
==
1
:
block
=
blocks
[
0
]
# HACK violate abstraction to avoid assertion error
if
block
.
xmodule_runtime
is
not
None
and
block
.
course_id
is
not
None
:
try
:
return
block
.
course_id
except
UndefinedContext
:
pass
except
ItemNotFoundError
:
pass
# if we get here, it must be in a Locator based store, but we won't be able to find
...
...
common/lib/xmodule/xmodule/x_module.py
View file @
e972b230
...
...
@@ -26,6 +26,7 @@ from xmodule.errortracker import exc_info_to_str
from
xmodule.modulestore
import
Location
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
,
InsufficientSpecificationError
,
InvalidLocationError
from
xmodule.modulestore.locator
import
BlockUsageLocator
from
xmodule.exceptions
import
UndefinedContext
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -795,7 +796,8 @@ class XModuleDescriptor(XModuleMixin, HTMLSnippet, ResourceTemplates, XBlock):
Returns the XModule corresponding to this descriptor. Expects that the system
already supports all of the attributes needed by xmodules
"""
assert
self
.
xmodule_runtime
is
not
None
if
self
.
xmodule_runtime
is
None
:
raise
UndefinedContext
()
assert
self
.
xmodule_runtime
.
error_descriptor_class
is
not
None
if
self
.
xmodule_runtime
.
xmodule_instance
is
None
:
try
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment