diff --git a/contentcuration/contentcuration/management/commands/mark_incomplete.py b/contentcuration/contentcuration/management/commands/mark_incomplete.py index f0b2962f86..95b4702834 100644 --- a/contentcuration/contentcuration/management/commands/mark_incomplete.py +++ b/contentcuration/contentcuration/management/commands/mark_incomplete.py @@ -25,7 +25,7 @@ def handle(self, *args, **options): # Mark invalid titles titlestart = time.time() logging.info('Marking blank titles...') - count = ContentNode.objects.exclude(complete=False).filter(title='').order_by().update(complete=False) + count = ContentNode.objects.exclude(complete=False).filter(title='', parent__isnull=False).order_by().update(complete=False) logging.info('Marked {} invalid titles (finished in {})'.format(count, time.time() - titlestart)) # Mark invalid licenses diff --git a/contentcuration/contentcuration/utils/publish.py b/contentcuration/contentcuration/utils/publish.py index d5aaadb873..71558f759d 100644 --- a/contentcuration/contentcuration/utils/publish.py +++ b/contentcuration/contentcuration/utils/publish.py @@ -22,6 +22,7 @@ from django.db.models import Count from django.db.models import Q from django.db.models import Sum +from django.db.utils import IntegrityError from django.template.loader import render_to_string from django.utils import timezone from django.utils.translation import gettext_lazy as _ @@ -125,7 +126,7 @@ def assign_license_to_contentcuration_nodes(channel, license): channel.main_tree.get_family().update(license_id=license.pk) -def map_content_nodes( +def map_content_nodes( # noqa: C901 root_node, default_language, channel_id, @@ -140,6 +141,9 @@ def map_content_nodes( # make sure we process nodes higher up in the tree first, or else when we # make mappings the parent nodes might not be there + if not root_node.complete: + raise ValueError("Attempted to publish a channel with an incomplete root node") + node_queue = collections.deque() node_queue.append(root_node) @@ -566,6 +570,8 @@ def map_prerequisites(root_node): target_node.has_prerequisite.add(n['prerequisite__node_id']) except kolibrimodels.ContentNode.DoesNotExist as e: logging.error('Unable to find prerequisite {}'.format(str(e))) + except IntegrityError as e: + logging.error('Unable to find source node for prerequisite relationship {}'.format(str(e))) def map_channel_to_kolibri_channel(channel):