Skip to content

Commit

Permalink
Do inheritance skipping properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
rtibbles committed Aug 23, 2024
1 parent cb0e61b commit 8e6a56a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 4 additions & 0 deletions contentcuration/contentcuration/tests/test_exportchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def setUp(self):
super(ExportChannelTestCase, self).setUp()
self.content_channel = channel()

# Make a ricecooker channel to test inheritance behaviour
self.content_channel.ricecooker_version = "0.7.1"
self.content_channel.save()

# Add some incomplete nodes to ensure they don't get published.
new_node = create_node({'kind_id': 'topic', 'title': 'Incomplete topic', 'children': []})
new_node.complete = False
Expand Down
6 changes: 2 additions & 4 deletions contentcuration/contentcuration/utils/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,10 @@ def map_nodes(self):

def _gather_inherited_metadata(self, node, inherited_fields):
metadata = {}
if not self.inherit_metadata:
return metadata

for field in inheritable_map_fields:
metadata[field] = {}
inherited_keys = (inherited_fields.get(field) or {}).keys()
inherited_keys = (inherited_fields.get(field) or {}).keys() if self.inherit_metadata else []
own_keys = (getattr(node, field) or {}).keys()
# Get a list of all keys in reverse order of length so we can remove any less specific values
all_keys = sorted(set(inherited_keys).union(set(own_keys)), key=len, reverse=True)
Expand All @@ -240,7 +238,7 @@ def _gather_inherited_metadata(self, node, inherited_fields):
metadata[field][key] = True

for field in inheritable_simple_value_fields:
if field in inherited_fields:
if self.inherit_metadata and field in inherited_fields:
metadata[field] = inherited_fields[field]
if getattr(node, field):
metadata[field] = getattr(node, field)
Expand Down

0 comments on commit 8e6a56a

Please sign in to comment.