Skip to content

feat!: reference course scopes by course key instead of a foreign key - #627

Draft
mariajgrimaldi wants to merge 2 commits into
MJG/coursescope-key-adrfrom
MJG/coursescope-drop-fk
Draft

mariajgrimaldi wants to merge 2 commits into
MJG/coursescope-key-adrfrom
MJG/coursescope-drop-fk

Conversation

@mariajgrimaldi

@mariajgrimaldi mariajgrimaldi commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Description

Following ADR 0035 (#625), CourseScope references its course only through the course key in external_key, so the framework's schema no longer depends on the platform's course table.

  • Scopes are created and found by external_key, and course_overview becomes a read-only property that returns the course, or None while it doesn't exist.
  • A post_delete receiver on the course model deletes the course's scope and its role assignments, as the foreign key cascade did.
  • Migration 0013_remove_coursescope_course_overview copies the key of older scopes into external_key and removes the column. When a key collides with another scope's key, it stops before removing the column and names a new how-to that resolves the conflict.

This is a breaking change, since filtering or creating scopes with course_overview and CourseOverview.authz_scopes no longer work, and the equivalent is external_key=str(course.id). A code search across the openedx organization found no uses outside this repo (CourseScope, authz_scopes). Migrating back below 0013 adds the foreign key again, so it fails with error 3780 on the databases from #593.

Related to #593.

Testing instructions

  1. Run the test suite. The migration tests migrate back to 0012, create course scopes with and without keys, and run 0013, including a key conflict.
  2. On a MySQL database with course scopes and role assignments from Verawood, mount this branch in Tutor and run ./manage.py lms migrate. Every user keeps the same roles, and openedx_authz_coursescope has no course_overview_id column.
  3. Delete a course in Studio and check that its course scope and role assignments are gone.
  4. Where 0013 reports conflicting scopes, follow the how-to and run ./manage.py lms migrate again. It finishes, and the remaining scope has the role assignments of both.

Merge checklist:
Check off if complete or not applicable:

  • 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 Nov 16, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @mariajgrimaldi!

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.

🔘 Update the status of your PR

Your PR is currently marked as a draft. After completing the steps above, update its status by clicking "Ready for Review", or removing "WIP" from the title, as appropriate.


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 Nov 16, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Nov 16, 2026
@mariajgrimaldi
mariajgrimaldi force-pushed the MJG/coursescope-drop-fk branch from b8d3e98 to b3ce762 Compare November 18, 2026 12:45
@mariajgrimaldi
mariajgrimaldi removed this pull request from stack #629 November 18, 2026 13:12
@mariajgrimaldi
mariajgrimaldi force-pushed the MJG/coursescope-drop-fk branch from b3ce762 to 630340a Compare November 18, 2026 13:12
@mariajgrimaldi
mariajgrimaldi changed the base branch from MJG/fix-coursescope-fk to MJG/coursescope-key-adr November 18, 2026 13:13
Django ran the copy step in a transaction, so the error raised on a conflict also rolled back the keys copied before it, while the docstring, the how-to and ADR 0035 say they stay.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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: Waiting on Author

Development

Successfully merging this pull request may close these issues.

2 participants