Skip to content

Commit 977e37d

Browse files
committed
Prevent syncing from incomplete source node
1 parent 050e85b commit 977e37d

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

contentcuration/contentcuration/tests/test_contentnodes.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,27 @@ def test_sync_after_no_changes(self):
824824
)
825825
self._assert_same_files(orig_video, cloned_video)
826826

827+
def test_sync_but_incomplete(self):
828+
orig_video, cloned_video = self._setup_original_and_deriative_nodes()
829+
orig_video.license_id = None
830+
orig_video.mark_complete()
831+
self.assertFalse(orig_video.complete)
832+
orig_video.save()
833+
834+
self.assertTrue(cloned_video.complete)
835+
836+
sync_node(
837+
cloned_video,
838+
sync_titles_and_descriptions=True,
839+
sync_resource_details=True,
840+
sync_files=True,
841+
sync_assessment_items=True,
842+
)
843+
844+
self.assertIsNotNone(cloned_video.license_id)
845+
cloned_video.mark_complete()
846+
self.assertTrue(cloned_video.complete)
847+
827848
def test_sync_with_subs(self):
828849
orig_video, cloned_video = self._setup_original_and_deriative_nodes()
829850
self._add_subs_to_video_node(orig_video, "fr")
@@ -868,6 +889,13 @@ def _create_video_node(self, title, parent, withsubs=False):
868889
node_id="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
869890
)
870891
video_node = testdata.node(data, parent=parent)
892+
video_node.license_id = 9 # Special Permissions
893+
video_node.license_description = "Special permissions for testing"
894+
video_node.copyright_holder = "LE"
895+
# ensure the node is complete according to our logic
896+
video_node.mark_complete()
897+
self.assertTrue(video_node.complete)
898+
video_node.save()
871899

872900
if withsubs:
873901
self._add_subs_to_video_node(video_node, "fr")

contentcuration/contentcuration/utils/sync.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ def sync_node(
5353
sync_assessment_items=False,
5454
):
5555
original_node = node.get_original_node()
56+
if not original_node.complete:
57+
logging.warning(f"Refusing to sync from incomplete node: {node.pk}")
58+
return node
5659
if original_node.node_id != node.node_id: # Only update if node is not original
5760
logging.info(
58-
"----- Syncing: {} from {}".format(
59-
node.title, original_node.get_channel().name
60-
)
61+
f"----- Syncing: {node.title} from {original_node.get_channel().name}"
6162
)
6263
if sync_titles_and_descriptions:
6364
fields = [

0 commit comments

Comments
 (0)