Allow channel version downgrades when importing via version token
❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.
Overview
Kolibri currently blocks importing a channel version older than what's already installed. This needs to be relaxed to allow downgrades when a specific version is requested via token — for example, reverting a draft channel to the latest published version, or downgrading from a private token version to the approved community library version.
Complexity: Medium Target branch: release-v0.19.x
Context
The version gate is in kolibri/core/content/utils/channel_import.py:check_and_delete_existing_channel (line 761-762). It only allows import when current_version < self.channel_version, cancelling the import otherwise.
The upgrade diff stats in kolibri/core/content/utils/upgrade.py:diff_stats calculate new/deleted/updated resources by comparing two database states. The comparison logic itself is directionally agnostic — it compares what's in the local DB vs what's in the remote DB — but the naming and framing assumes an upgrade.
RemoteChannelDiffStatsValidator in kolibri/core/content/tasks.py stores new_channel_version in job metadata from the v1 lookup response.
The Change
Relax the version check in check_and_delete_existing_channel to allow importing an older version when a specific version was requested via token. The existing cleanup logic (deleting old channel tree data) should apply in both upgrade and downgrade directions.
Verify that the diff stats logic in upgrade.py works correctly for downgrades — the comparison is between two database states regardless of version direction, but naming/framing may need adjustment to avoid confusion.
How to Get There
The version check in channel_import.py:check_and_delete_existing_channel (line 761) currently gates on current_version < self.channel_version. When a version was explicitly requested via token, this check should allow current_version != self.channel_version (both upgrades and downgrades). The channel_version from the token metadata (threaded through via #14588) indicates an explicit version request.
The diff stats in upgrade.py:diff_stats should work without changes — it compares local vs remote DB states regardless of direction. Verify this and adjust any misleading naming if needed.
Acceptance Criteria
- [ ] Importing an older version is allowed when a specific version was requested via token
- [ ] Importing an older version without an explicit version token continues to be blocked
- [ ] Channel tree data is correctly cleaned up during downgrades
- [ ] Diff stats work correctly for downgrades (new/deleted/updated resources are accurate)
Testing
- [ ] Extend
ImportChannelTestCaseto cover downgrade when a version token is provided - [ ] Extend
ImportChannelTestCaseto verify downgrade is still blocked without a version token - [ ] Verify diff stats produce correct results when downgrading
AI usage
Used Claude Code to draft this issue interactively. I provided the requirements and Claude explored the Kolibri channel import and upgrade code to understand the version gating and diff stats logic. All content reflects my decisions and was reviewed section by section.
Watching for resolution on behalf of learningequality/kolibri#14592.
Plan: Allow importing an older channel version when a specific version is explicitly requested (signalled by version_requested=True), while keeping the existing block for unintended downgrades.
- [ ] Add
version_requestedtoChannelImportand relax the version gate - [ ] Thread
version_requestedthroughinitialize_import_managerand local-db helpers - [ ] Thread
version_requestedthroughchannel_transfer.pyand task validators - [ ] Pass
version_requested=Trueindiff_statsand add tests
@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly
How was this generated?
- Implemented code following the pre-approved plan using test-driven development (red-green-refactor)
- Ran the project's full test suite and linter before committing
- For UI changes: captured live screenshots to verify rendering
- For backend changes: verified with example API/CLI output
Fixed in #14609