Skip to content

Populate draft ChannelVersion metadata fields during draft publish #5839

@AlexVelezLl

Description

@AlexVelezLl

This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Overview

fill_published_fields is only called during non-draft channel publishes, leaving draft ChannelVersion objects (those with version=None) without computed metadata (resource count, size, kind count, languages, licenses, categories). Code that relies on this metadata being set breaks or returns stale values when a channel has only been published as a draft.

Complexity: Low
Target branch: unstable

Context

fill_published_fields (in contentcuration/utils/publish.py) computes resource count, kind count, size, included languages, licenses, and categories, then writes them to:

  1. The channel object's own fields (e.g. total_resource_count, published_size)
  2. channel.published_data — a dict keyed by version number storing historical publish snapshots
  3. channel.version_info — a ChannelVersion FK pointing to the currently-published version's record

Draft publishes create a ChannelVersion with version=None (via create_draft_channel_version), but this object is never populated with the computed metadata. For draft publishes, items 1, 2, and 3 above must not be updated — total_resource_count and published_size on the channel reflect the live published state, published_data tracks real published version snapshots, and version_info points to the live published version. None of these should be affected by a draft publish.

The Change

fill_published_fields should also be invoked when publishing a draft version. However, for draft publishes it must only populate the draft ChannelVersion object (the one with version=None) — setting its resource_count, size, kind_count, included_languages, included_licenses, included_categories, and related fields — without modifying channel.published_data, channel.version_info, channel.total_resource_count, or channel.published_size.

Two additional constraints for draft publishes:

  • Special permissions: on each draft publish, special_permissions_included on the draft ChannelVersion must be fully replaced (not accumulated) — a second draft publish should not carry over special permissions licenses from a previous draft publish that are no longer present.
  • Distributable flag: the call to AuditedSpecialPermissionsLicense.mark_channel_version_as_distributable (currently triggered when channel.public) must be skipped for draft publishes.

Acceptance Criteria

General

  • fill_published_fields (or equivalent extracted helper) is called during draft publishes
  • The draft ChannelVersion object (version=None) has resource_count, size, kind_count, included_languages, included_licenses, included_categories, and related fields populated after a draft publish
  • channel.published_data is not modified during a draft publish
  • channel.version_info is not updated during a draft publish
  • channel.total_resource_count and channel.published_size are not overwritten during a draft publish
  • A non-draft publish continues to work exactly as before — all channel fields, published_data, and version_info are still populated correctly
  • On a second consecutive draft publish, special_permissions_included on the draft ChannelVersion reflects only the current publish — licenses from the previous draft publish that are no longer present are removed
  • AuditedSpecialPermissionsLicense.mark_channel_version_as_distributable is not called during a draft publish, even if channel.public is True

Testing

  • Unit tests cover that draft ChannelVersion metadata fields are populated after a draft publish
  • Unit tests cover that channel.published_data, channel.version_info, channel.total_resource_count, and channel.published_size are unchanged after a draft publish
  • Unit test covers that a second draft publish replaces (not accumulates) special_permissions_included on the draft ChannelVersion
  • Unit test covers that mark_channel_version_as_distributable is not called during a draft publish for a public channel
  • Existing publish tests continue to pass

References

  • publish_channel and fill_published_fieldscontentcuration/contentcuration/utils/publish.py
  • ChannelVersion model — contentcuration/contentcuration/models.py
  • create_draft_channel_versioncontentcuration/contentcuration/utils/publish.py

AI usage

Drafted with Claude Code. The issue structure, context, and acceptance criteria were derived from reading the relevant source files directly. Content was reviewed and edited for accuracy before submission.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions