Skip to content

openedx_authz.0007_coursescope fails with MySQL error 3780 on databases whose default collation is not utf8mb4_unicode_ci (e.g. MySQL 8 default utf8mb4_0900_ai_ci) #593

In review

Description

@holaontiveros

Summary

Upgrading an existing Ulmo instance to Verawood fails during ./manage.py lms migrate at
openedx_authz.0007_coursescope when the database's default collation is MySQL 8's
utf8mb4_0900_ai_ci (the default on MySQL 8 and on AWS RDS) instead of Tutor's utf8mb4_unicode_ci.

Error

django.db.utils.OperationalError: (3780, "Referencing column 'course_overview_id' and
referenced column 'id' in foreign key constraint
'openedx_authz_course_course_overview_id_e73fe24b_fk_course_ov' are incompatible.")

Environment

  • edx-platform release/verawood, openedx-authz 1.23.0, edx-opaque-keys 4.0.0
  • MySQL 8.0.42 on AWS RDS, external DB (Tutor 22.0.2, RUN_MYSQL=false)
  • Server / database default collation: utf8mb4_0900_ai_ci
  • Long-lived database (first migrations applied in 2021), already fully utf8mb4

Root cause

  • Since opaque-keys 3.1.0 (opaque-keys#426),
    OpaqueKeyField.db_parameters() emits an explicit collation on MySQL:
    utf8mb4_unicode_ci (or utf8mb4_bin when case_sensitive=True).
  • A ForeignKey copies the target field's db_parameters, so the new
    openedx_authz_coursescope.course_overview_id column is created as
    varchar(255) COLLATE utf8mb4_unicode_ci.
  • The existing course_overviews_courseoverview.id was created before that change and is
    varchar(255) COLLATE utf8mb4_0900_ai_ci. docs: defer authorization implication semantics #426 intentionally generated no migration for
    existing columns.
  • MySQL refuses a FK between varchar columns of different collations, so the migration fails.

Native Tutor installs don't hit this because Tutor's MySQL runs with
--collation-server=utf8mb4_unicode_ci (tutor#1084).
tutor do convert-mysql-utf8mb4-charset does not help here: it refuses to run when
RUN_MYSQL=false and only converts utf8mb3_* collations.

Side effect

MySQL DDL is not transactional: the failed run leaves openedx_authz_coursescope created
but 0007 unrecorded, so the next migrate fails with
(1050, "Table 'openedx_authz_coursescope' already exists") until the table is dropped manually.

Steps to reproduce

  1. MySQL 8 with default collation utf8mb4_0900_ai_ci.
  2. Install Ulmo and run migrations (course_overviews_courseoverview.id gets utf8mb4_0900_ai_ci).
  3. Upgrade to Verawood and run ./manage.py lms migrate.

Possible fixes (for discussion)

  1. In 0007_coursescope, create course_overview_id with the collation of the referenced
    column as it exists in the database, instead of the one derived from the model.
  2. In opaque-keys, only emit an explicit collation when case_sensitive=True, or make the
    case-insensitive collation configurable by a setting.
  3. At minimum, document in the Verawood release notes that operators whose database default
    is not utf8mb4_unicode_ci must align course_overviews_courseoverview.id before upgrading.

Related, non-blocking

New columns created with the explicit utf8mb4_unicode_ci collation raise
1267 Illegal mix of collations when compared column-to-column with existing
utf8mb4_0900_ai_ci columns (e.g. edx_when_userdate.first_component_block_id vs
edx_when_contentdate.location). No current code joins those, but the risk will grow
as more such columns are added.

Activity

  1. added
    bug
    on Nov 5, 2026
  2. added
    release blocker
    on Nov 6, 2026
  3. moved this from In Grooming to In Progress in RBAC AuthZ Boardon Nov 12, 2026
  4. bradenmacdonald commented on Nov 19, 2026

    @bradenmacdonald

    We discussed this in a meeting yesterday: the recommended fix is to update the CourseScope table so that it has an integer foreign key to the CourseRun table, rather than a string foreign key to the CourseOverview table. Integer foreign keys do not have collation conflict problems, and will be more efficient than a string key anyways. In fact, nobody should be making foreign keys to CourseOverview at all going forward, now that CourseRun is available.

    However, we don't want openedx-core to be a dependency of openedx-authz; rather openedx-authz should be a dependency of openedx-core. So it might be necessary to move the CourseScope model into openedx-core in order to make this work. (Keeping the base Scope class in authz.)

  5. mariajgrimaldi commented on Nov 20, 2026

    @mariajgrimaldi
    Member

    Thanks for sharing! I think the ideal is for the framework not to depend on how scopes are modeled in specific applications, either by not referencing them at all or by providing an interface that applications can implement (which we already offer by subclassing the base scope classes), so moving CourseScope into openedx-core would align with this principle.

    For Verawood, I think we're going with the less aggressive approach of keeping the reference to courses through CourseOverview and only fixing 0007 for the installs that are failing, since we want to avoid a breaking change.

    For Willow, we can deprecate the CourseOverview reference, and it makes sense to move CourseScope to openedx-core with a foreign key to CourseRun, since that domain owns courses. My proposal for Willow was to drop the foreign key to CourseOverview altogether and reference courses only by their course key, but it's only a proposal for now so we can discuss it in the ADR: #625

    What do you think?

  6. bradenmacdonald commented on Nov 20, 2026

    @bradenmacdonald

    I don't have a strong opinion on those questions, so let's see what others think.

  7. moved this from In Progress to Done in RBAC AuthZ Boardon Nov 26, 2026
  8. added
    willow
    on Nov 26, 2026
  9. mariajgrimaldi commented on Nov 27, 2026

    @mariajgrimaldi
    Member

    This is partially solved for Verawood by: openedx/openedx-platform#39447. We'll be working on a long-term solution for Willow and later releases.

  10. added
    willow
    and removed
    willow
    on Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugrelease blockerwillow

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions