From 710927f961a0408ce282946fead8d55cfa969535 Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Wed, 6 Nov 2024 15:16:35 -0800 Subject: [PATCH 1/2] Add two defensive programming checks to stop 500s when getting channel details. --- contentcuration/contentcuration/models.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/contentcuration/contentcuration/models.py b/contentcuration/contentcuration/models.py index 690325fc3c..60c83371cb 100644 --- a/contentcuration/contentcuration/models.py +++ b/contentcuration/contentcuration/models.py @@ -1570,12 +1570,15 @@ def get_details(self, channel_id=None): .values("id") ) + # Get resources + resources = descendants.exclude(kind=content_kinds.TOPIC).order_by() + if channel_id: channel = Channel.objects.filter(id=channel_id)[0] else: channel = self.get_channel() - if not descendants.exists(): + if not resources.exists(): data = { "last_update": pytz.utc.localize(datetime.now()).strftime( settings.DATE_TIME_FORMAT @@ -1604,8 +1607,6 @@ def get_details(self, channel_id=None): cache.set("details_{}".format(self.node_id), json.dumps(data), None) return data - # Get resources - resources = descendants.exclude(kind=content_kinds.TOPIC).order_by() nodes = With( File.objects.filter(contentnode_id__in=Subquery(resources.values("id"))) .values("checksum", "file_size") @@ -1816,10 +1817,10 @@ def get_details(self, channel_id=None): "sample_pathway": pathway, "sample_nodes": sample_nodes, # source model fields for the below default to an empty string, but can also be null - "authors": list(filter(bool, node["authors"])), - "aggregators": list(filter(bool, node["aggregators"])), - "providers": list(filter(bool, node["providers"])), - "copyright_holders": list(filter(bool, node["copyright_holders"])), + "authors": list(filter(bool, node["authors"] or [])), + "aggregators": list(filter(bool, node["aggregators"] or [])), + "providers": list(filter(bool, node["providers"] or [])), + "copyright_holders": list(filter(bool, node["copyright_holders"] or [])), "levels": node.get("levels") or [], "categories": node.get("all_categories") or [], } From e18df39d31facaf6f9314cec5e7376bbad453ae1 Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Wed, 6 Nov 2024 15:17:05 -0800 Subject: [PATCH 2/2] Require the root node to have descendant resources, not just descendant nodes in order to publish. --- .../frontend/channelEdit/views/TreeView/TreeViewBase.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contentcuration/contentcuration/frontend/channelEdit/views/TreeView/TreeViewBase.vue b/contentcuration/contentcuration/frontend/channelEdit/views/TreeView/TreeViewBase.vue index 2de7cae031..0f8ba07b3c 100644 --- a/contentcuration/contentcuration/frontend/channelEdit/views/TreeView/TreeViewBase.vue +++ b/contentcuration/contentcuration/frontend/channelEdit/views/TreeView/TreeViewBase.vue @@ -390,7 +390,7 @@ this.currentChannel.publishing || !this.isChanged || !this.currentChannel.language || - (this.rootNode && !this.rootNode.total_count) + (this.rootNode && !this.rootNode.resource_count) ); }, publishButtonTooltip() {