Skip to content

docs: add ADR for course authoring automatic migration#251

Open
BryanttV wants to merge 1 commit intoopenedx:mainfrom
eduNEXT:bav/adr-0013-automatic-migration
Open

docs: add ADR for course authoring automatic migration#251
BryanttV wants to merge 1 commit intoopenedx:mainfrom
eduNEXT:bav/adr-0013-automatic-migration

Conversation

@BryanttV
Copy link
Copy Markdown
Contributor

@BryanttV BryanttV commented Apr 9, 2026

Related issue: #223

Description

This PR adds ADR 0013 - Course Authoring Automatic Migration, proposing an automatic and asynchronous migration mechanism triggered by changes in the authz.enable_course_authoring feature flag,

Merge checklist

Check off if complete or not applicable:

  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Fixup commits are squashed away
  • Unit tests added/updated
  • Manual testing instructions provided
  • Noted any: Concerns, dependencies, migration issues, deadlines, tickets

@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 Apr 9, 2026
@openedx-webhooks
Copy link
Copy Markdown

openedx-webhooks commented Apr 9, 2026

Thanks for the pull request, @BryanttV!

This repository is currently maintained by @openedx/committers-openedx-authz.

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 Apr 9, 2026
@BryanttV BryanttV changed the title docs: add course authoring automatic migration adr docs: add ADR for course authoring automatic migration Apr 9, 2026
@BryanttV BryanttV marked this pull request as ready for review April 9, 2026 18:39
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Apr 9, 2026
Copy link
Copy Markdown
Contributor

@rodmgwgu rodmgwgu left a comment

Choose a reason for hiding this comment

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

Looking good, just some comments, thanks!

- ``authz_rollback_course_authoring`` (rollback migration)

In `ADR 0011`_ and `ADR 0010`_ it was established that migration must occur automatically when
the feature flag ``authz.enable_course_authoring`` changes state, but they deferred the definition of
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: "but the definition of the specific mechanism was deferred"


.. code:: python

ENABLE_AUTOMATIC_COURSE_AUTHORING_MIGRATION = False
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like this approach, however I'm wondering if we should be more specific in the setting name so it's clear that it relates to Authz? like ENABLE_AUTOMATIC_AUTHZ_COURSE_AUTHORING_MIGRATION.


.. code:: python

class CourseAuthoringMigrationRun(models.Model):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here, should we be more specific like "AuthzCourseAuthoringMigrationRun"?


lock_key = f"authz_migration:{scope_type}:{scope_key}"

The lock is acquired using ``cache.add()``, which is an atomic operation. The default TTL
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What happens when there is a lock and we change the flag again? would it enter a queue and execute when the lock is freed?

Comment on lines +30 to +31
- **No concurrency protection**: Multiple concurrent flag changes can trigger overlapping
migrations, leading to race conditions and data corruption.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a bit contradictory, given that we currently don't have this automation and the ADR proposes it. This concurrency issue arises only with the automation.

the feature flag ``authz.enable_course_authoring`` changes state, but they deferred the definition of
the specific mechanism. This ADR addresses that gap.

The current manual approach presents the following risks:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I want to make sure I understand the need for a different mechanism than a 1-time migration or a more controlled migration that on-demand job operators could use. I'm thinking of a mechanism like in forums V2, when the storage backend is changed:

  1. If the flag is on during initialization (tutor), then the migration is executed
  2. If not then not much happens
  3. If there's a failure during the migration, then automatically rollback

Why is this not an acceptable solution, given that it directly impacts operators and that they can manage this kind of controlled migration better than in a live environment?

Comment on lines +92 to +93
The existing utility functions ``migrate_legacy_course_roles_to_authz`` and
``migrate_authz_to_legacy_course_roles`` will be modified to incorporate the locking strategy
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think these functions should stay agnostic of the locking strategy, no? Their only job is to migrate data like any other migration command. Maybe we can encapsulate the utility functions in another function that ensures these migrations run asynchronously and 1 at a time. What do you think?

nit: also, this I don't think should be utilities anymore so I don't know if we should move them elsewhere

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We could have a safe migration with the lock that calls this utility functions and manages the locks, and auditability so these functions stay with a single responsibility.

2. Migration Trigger (Django Signals)
-------------------------------------

``pre_save`` signal handlers are attached to ``WaffleFlagCourseOverrideModel`` and
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not post_save instead?

migration_type = models.CharField(max_length=20) # forward / rollback
scope_type = models.CharField(max_length=20) # course / org
scope_key = models.CharField(max_length=255)
status = models.CharField(max_length=20) # pending, running, completed, skipped
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If it failed how would I get the exact log / error?

unexpectedly on instances where operators have not explicitly accepted the risks.

Negative consequences / risks
==============================
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The main risk for me here still is a data migration in a live instance which is not a controlled environment.

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.

5 participants