Skip to content

Conversation

@nucleogenesis
Copy link
Member

Summary

Adds a create_channel_versions command that uses the published_data dict on Channels to create new ChannelVersion instances.

I worked out the initial approach and some simple tests myself and asked Claude to help extrapolate the tests I made to include checks for things like the Audited license models and such.

References

Closes #5593

Reviewer guidance

Have I missed anything?

@nucleogenesis nucleogenesis force-pushed the esocc--channel-version-command branch from 4cf92bc to d895d69 Compare January 22, 2026 23:10
@nucleogenesis nucleogenesis force-pushed the esocc--channel-version-command branch from d895d69 to a70ad56 Compare January 23, 2026 00:45
Comment on lines +330 to +334
def test_channel_with_existing_special_permissions_in_published_data(self):
"""
If published_data already contains special_permissions_included,
the command should not recompute it.
"""
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels right even though I don't think this would run into the problem unless we fail and rerun it - I'm not sure what the plan for running the command would look like so guidance there would be greatly appreciated!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is right just as it is now! This could be replicated in unstable since we already have some AuditedSpecialPermissionsLicense created there, but the behavior is correct!

Copy link
Member

@AlexVelezLl AlexVelezLl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @nucleogenesis! Just noted a couple of things that I didn't note while writing the issue 😅.

Comment on lines +330 to +334
def test_channel_with_existing_special_permissions_in_published_data(self):
"""
If published_data already contains special_permissions_included,
the command should not recompute it.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is right just as it is now! This could be replicated in unstable since we already have some AuditedSpecialPermissionsLicense created there, but the behavior is correct!

# to the most recent ChannelVersion instance
for channel in channels.iterator():
logging.info(f"Processing channel {channel.id}")
last_created_ch_ver = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it seems that this method is working fine, I am not sure if we can rely on the channel.published_data.values()returning always the most recent version at the end. I think a safer approach could be to check if pub_data.get("version") === channel.version.

Comment on lines +148 to +157
last_created_ch_ver = ChannelVersion.objects.create(
channel=channel,
version=pub_data.get("version"),
included_categories=pub_data.get("included_categories", []),
included_licenses=pub_data.get("included_licenses"),
included_languages=pub_data.get("included_languages"),
non_distributable_licenses_included=pub_data.get(
"non_distributable_licenses_included"
),
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, apologies, I didn't specify this in the issue 😅, the ChannelVersion model has more fields besides the ones we need to compute here. Here, you can see all values we set to the channelVersion object on the publish flow, so we would need to set all of them here too.

Additionally, just to play safe, I think we can use the create_or_update method so that in case the command is re-run or in case we have some channel versions already set up (in unstable, for example), it doesn't fail because channel and version are unique together.

logging.info(
f"Validating published data for channel {channel.id} version {pub_data['version']}"
)
special_permissions = validate_published_data(pub_data, channel)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting that validate_published_data is updating the published_data object by computing properties using the current published_nodes, which means that these computed properties only belong to the most recent version. Therefore, annotating these properties in previous versions would be an error. Since we don't need previous versions to have these computed properties, we don't need to care about computing them, and we can just call this validate_published_data if pub_data corresponds to the current channel version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ESoCC: Create migration command to create ChannelVersion models for old channels

2 participants