Skip to content

Comments

Upgrade to opaque-keys 3.1, fix: duplicate course ID detection was not working [FC-0117]#38044

Open
bradenmacdonald wants to merge 2 commits intoopenedx:masterfrom
open-craft:braden/opaque-keys-3.1
Open

Upgrade to opaque-keys 3.1, fix: duplicate course ID detection was not working [FC-0117]#38044
bradenmacdonald wants to merge 2 commits intoopenedx:masterfrom
open-craft:braden/opaque-keys-3.1

Conversation

@bradenmacdonald
Copy link
Contributor

@bradenmacdonald bradenmacdonald commented Feb 23, 2026

Description

This PR pulls in opaque-keys 3.1 to get openedx/opaque-keys#426

I'm mostly opening it to confirm that everything is working fine using a pre-release version of 3.1, and make sure all the tests are passing (albeit on SQLite only).

But this PR also:

  • Removes some now-redundant max_length=255 specifiers
  • Includes an example of converting a field (modulestore_migrator.ModulestoreBlockSource.key) to be case-sensitive
  • Pulls in the changes from fix: duplicate course ID detection was not working #38030 and uses the new case_sensitive=True on that model's key field as well.
    • I wasn't planning to combine these PRs, but the SplitModulestoreCourseIndexTest::test_course_id_case_sensitive test was failing without those changes, because the test expected course_id to be case-sensitive (due to setting the collation for MySQL in a migration, and that being the default on MySQL), but this new version of opaque-keys changes the default on SQLite to case-insensitive. If you prefer to keep the PRs separate, I could just disable that test and re-enable it when merging the other PR, or merge the other PR first.

Supporting information

See the related opaque-keys PR.

Testing instructions

Simplest thing is to go to http://studio.local.openedx.io:8001/admin/modulestore_migrator/modulestoresource/ and test that before this PR, you cannot create a "modulestore source" that differs only in case from an existing one, and afterward you can. Demonstrating that the field has become case-sensitive. This modulestore_migrator is the only app where I've made a change, and everything else in the platform should be working exactly as it was before when run/tested on MySQL.

@bradenmacdonald bradenmacdonald requested a review from a team as a code owner February 23, 2026 23:45
@bradenmacdonald bradenmacdonald added the FC Relates to an Axim Funded Contribution project label Feb 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 Feb 23, 2026
@openedx-webhooks
Copy link

Thanks for the pull request, @bradenmacdonald!

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

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.

1 similar comment
@openedx-webhooks
Copy link

Thanks for the pull request, @bradenmacdonald!

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

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.

query_counts = [52, 46, 46, 46, 46, 46, 46, 46, 46, 46, 16]
ordered_course_ids = sorted([str(cid) for cid in (course_ids + [c.id for c in self.courses])])
query_counts = [57, 46, 46, 46, 46, 46, 46, 46, 46, 43, 12]
ordered_course_ids = sorted([str(cid) for cid in (course_ids + [c.id for c in self.courses])], key=str.lower)
Copy link
Contributor Author

@bradenmacdonald bradenmacdonald Feb 24, 2026

Choose a reason for hiding this comment

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

This test started failing after the opaque-keys upgrade. It's because we run tests on SQLite, and the default collation on SQLite is now case-insensitive. So the 3 courses created by the class whose org ID starts with uppercase are now sorted differently.

I believe this change of behavior would only affect SQLite and our tests are now reflecting the same behavior MySQL already had.

FAILED lms/djangoapps/course_api/tests/test_views.py::CourseListSearchViewTest::test_too_many_courses - AssertionError: assert ['course-v1:o...run0.13', ...] == ['course-v1:O...run0.10', ...]
  
  At index 0 diff: 'course-v1:org0+course0.0+run0.0' != 'course-v1:OrgA+DemoZ+2010_1'
  
  Full diff:
    [
  -     'course-v1:OrgA+DemoZ+2010_1',
  -     'course-v1:OrgB+DemoZ+2010_2',
  -     'course-v1:OrgC+DemoZ+2010_3',
        'course-v1:org0+course0.0+run0.0',
        'course-v1:org0+course0.1+run0.1',
        ... omitted for brevity...
        'course-v1:org0+course0.6+run0.6',
  +     'course-v1:org0+course0.7+run0.7',
  +     'course-v1:org0+course0.8+run0.8',
  +     'course-v1:org0+course0.9+run0.9',
    ]

As for the query count changes, I think it's because the three courses created by the class have different related objects loaded than all the other courses, so the per-page query count varies depending on which page they end up on. I don't know why the overall count decreased by 2.

@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Feb 24, 2026
Copy link
Member

@kdmccormick kdmccormick left a comment

Choose a reason for hiding this comment

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

Great! I tested by adding a case-duplicate course on master, then checking out this branch, trying to run your migration, watching it fail with an IntegrityError, deleting the case duplicate from split django modulestore admin, re-running the migration, and watching it succeed.

Could you mark at least one of the commits with ! and add a BREAKING CHANGE notice, and add a note to the Verawood ops notes page? https://openedx.atlassian.net/wiki/spaces/COMM/pages/5331222534/Verawood+-+Operator+Release+Notes . I know your PR is more of a bugfix than a standard breaking change; I just want to make it as likely as possible that operators with duplicate courses will know how to fix it rather than getting stuck on the IntegrityError in your migration.

bradenmacdonald added a commit to open-craft/openedx-platform that referenced this pull request Feb 24, 2026
…length (openedx#38044)

refactor: remove some 'max_length=255' to be more DRY

feat: example of making an OpaqueKeyField case_sensitive (modulestore_migrator)

test: update test now that we're using case-insensitive collation on SQLite
bradenmacdonald added a commit to open-craft/openedx-platform that referenced this pull request Feb 24, 2026
openedx#38044)

BREAKING CHANGE: this forces course IDs in modulestore to be unique (case insensitive). This was always supposed to be the case, but it wasn't working properly on MySQL. Upgrading past this commit may cause a migration failure if you have conflicting course IDs - see the migration 0004 docstring for details.
…length (openedx#38044)

refactor: remove some 'max_length=255' to be more DRY

feat: example of making an OpaqueKeyField case_sensitive (modulestore_migrator)

test: update test now that we're using case-insensitive collation on SQLite
openedx#38044)

BREAKING CHANGE: this forces course IDs in modulestore to be unique (case insensitive). This was always supposed to be the case, but it wasn't working properly on MySQL. Upgrading past this commit may cause a migration failure if you have conflicting course IDs - see the migration 0004 docstring for details.
@bradenmacdonald
Copy link
Contributor Author

Thanks @kdmccormick! I squashed this down to two commits, one of which is fix!: . Does that match what you were thinking?

@bradenmacdonald bradenmacdonald changed the title Upgrade to opaque-keys 3.1 [FC-0117] Upgrade to opaque-keys 3.1, fix: duplicate course ID detection was not working [FC-0117] Feb 24, 2026
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). FC Relates to an Axim Funded Contribution project 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.

3 participants