Commit a9697556 by Don Mitchell Committed by Adam Palay

Handle children pointers to non-existent children in has_changes

TNL-1141
parent 592665cc
...@@ -624,6 +624,9 @@ class DraftModuleStore(MongoModuleStore): ...@@ -624,6 +624,9 @@ class DraftModuleStore(MongoModuleStore):
return True return True
# if this block doesn't have changes, then check its children # if this block doesn't have changes, then check its children
elif xblock.has_children: elif xblock.has_children:
# fix a bug where dangling pointers should imply a change
if len(xblock.children) > len(xblock.get_children()):
return True
return any([self.has_changes(child) for child in xblock.get_children()]) return any([self.has_changes(child) for child in xblock.get_children()])
# otherwise there are no changes # otherwise there are no changes
else: else:
......
...@@ -268,8 +268,10 @@ class DraftVersioningModuleStore(SplitMongoModuleStore, ModuleStoreDraftAndPubli ...@@ -268,8 +268,10 @@ class DraftVersioningModuleStore(SplitMongoModuleStore, ModuleStoreDraftAndPubli
def has_changes_subtree(block_key): def has_changes_subtree(block_key):
draft_block = get_block(draft_course, block_key) draft_block = get_block(draft_course, block_key)
if draft_block is None: # temporary fix for bad pointers TNL-1141
return True
published_block = get_block(published_course, block_key) published_block = get_block(published_course, block_key)
if not published_block: if published_block is None:
return True return True
# check if the draft has changed since the published was created # check if the draft has changed since the published was created
......
...@@ -663,13 +663,18 @@ class TestMixedModuleStore(CourseComparisonTest): ...@@ -663,13 +663,18 @@ class TestMixedModuleStore(CourseComparisonTest):
self.assertTrue(self._has_changes(parent.location)) self.assertTrue(self._has_changes(parent.location))
self.assertTrue(self._has_changes(child.location)) self.assertTrue(self._has_changes(child.location))
@ddt.data('draft', 'split') @ddt.data(*itertools.product(
def test_has_changes_missing_child(self, default_ms): ('draft', 'split'),
(ModuleStoreEnum.Branch.draft_preferred, ModuleStoreEnum.Branch.published_only)
))
@ddt.unpack
def test_has_changes_missing_child(self, default_ms, default_branch):
""" """
Tests that has_changes() does not throw an exception when a child doesn't exist. Tests that has_changes() does not throw an exception when a child doesn't exist.
""" """
self.initdb(default_ms) self.initdb(default_ms)
with self.store.branch_setting(default_branch, self.course.id):
# Create the parent and point it to a fake child # Create the parent and point it to a fake child
parent = self.store.create_item( parent = self.store.create_item(
self.user_id, self.user_id,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment