Skip to content

feat: persist subsection prerequisites in course export/import - #39141

Open
Agrendalath wants to merge 2 commits into
openedx:masterfrom
open-craft:agrendalath/import-export-prerequisites
Open

Agrendalath wants to merge 2 commits into
openedx:masterfrom
open-craft:agrendalath/import-export-prerequisites

Conversation

@Agrendalath

@Agrendalath Agrendalath commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Description

Subsection prerequisites (Settings -> Advanced -> "Enable Subsection Prerequisites") are stored by the gating API as milestones, not in XBlock fields. As a result, they are lost when a course is exported and imported into a different instance, and course authors have to configure them again.

This PR carries the prerequisite settings through the OLX export and applies them back through the gating API on import. It supersedes #37475 and follows the conclusions of its review:

  • No new XBlock fields and no new child elements. The gating API still owns the settings.
  • The data is stored as attributes of <sequential>, like the other subsection settings.
  • The gating API is called directly, not through the XBlock service, which is not available in the export runtime.
  • The existing validation of the gating API is reused.
  • Malformed prerequisites fail the import with a clear message.
  • Requirements on subsections that are not in the archive are skipped with a warning. The dangling references are removed (the gating API deactivates them, so no data is lost).

OLX format

<sequential display_name="Prerequisite" is_prereq="true">...</sequential>
<sequential display_name="Gated" prereq="df2059964cbf47c5bbd6052855a5bb87"
            prereq_min_score="80" prereq_min_completion="90">...</sequential>
  • is_prereq: the subsection can be used as a prerequisite.
  • prereq: the url_name (block ID) of the required subsection, the same way child pointers reference blocks.
  • prereq_min_score and prereq_min_completion: omitted when empty.

The attributes are only used during import. They are never persisted in xml_attributes, so a later export cannot emit stale values.

Import behavior

The gating of the destination course is reconciled with the archive:

  • Subsections that are not part of the archive lose their gating. This also removes requirements pointing to them, so replacing a course with another leaves no orphaned milestones.
  • Subsections in the archive get the settings from their attributes. If the archive has no prerequisite attributes at all (meaning it predates this change), it keeps its existing settings, so restoring an old backup doesn't silently drop them.
  • An unknown or invalid prerequisite fails the import with a message naming the subsection, for example: Invalid prerequisite settings of the subsection "Gated" (...): "..." is not a subsection of this course.
  • Relationships that do not change are left untouched, so learners keep their fulfilled prerequisites.
  • Entrance exam and prerequisite course milestones are not affected.

Supporting information

Testing instructions

  1. In Studio, enable subsection prerequisites in the course's advanced settings.
  2. Mark subsection A as a prerequisite. Make subsection B require A with a minimum score and completion.
  3. Export the course and check sequential/<A>.xml and sequential/<B>.xml for the attributes above.
  4. Import the archive into a new course, enable subsection prerequisites there, and check that B requires A with the same values.
  5. Import an archive of a different course over the course from step 2. Check that no prerequisites remain.
  6. Remove the prerequisite attributes from the archive from step 3 and import it over the course from step 2. Check that the prerequisites are kept.

Automated tests:

pytest xmodule/tests/test_sequence.py xmodule/modulestore/tests/test_xml_importer.py \
  cms/djangoapps/contentstore/views/tests/test_import_export.py::TestCourseExportImportSubsectionPrerequisites
pytest --ds=lms.envs.test openedx/core/lib/gating/tests/test_api.py

Deadline

None.

Private-ref: BB-11256

@Agrendalath Agrendalath self-assigned this Sep 23, 2026
@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Sep 23, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @Agrendalath!

This repository is currently maintained by @openedx/wg-maintenance-openedx-platform-oncall.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Sep 23, 2026
@Agrendalath Agrendalath moved this from Needs Triage to Ready for Review in Contributions Sep 23, 2026
@Agrendalath
Agrendalath force-pushed the agrendalath/import-export-prerequisites branch 2 times, most recently from 532f654 to 16c64e2 Compare September 24, 2026 16:46
Export the subsection gating settings as attributes of the <sequential>
OLX element (is_prereq, prereq, prereq_min_score, prereq_min_completion)
and apply them through the gating API on course import.

On import, gating of subsections missing from the archive is removed.
Subsections present in the archive are reconciled with its attributes,
unless the archive has no prerequisite attributes at all (an export that
predates this change), in which case their existing settings are kept.
@Agrendalath
Agrendalath force-pushed the agrendalath/import-export-prerequisites branch from 16c64e2 to feac7b4 Compare September 24, 2026 16:46
@bradenmacdonald

Copy link
Copy Markdown
Contributor

@ormsbee this might be of interest to you

This branch has not been deployed

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

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Ready for Review

Development

Successfully merging this pull request may close these issues.

3 participants