From 8940da5efc74f247549ca83880fd9695c90925db Mon Sep 17 00:00:00 2001 From: ufedaseyeuconsultant Date: Wed, 7 Oct 2026 15:25:59 +0300 Subject: [PATCH 1/4] fix: match openedx-platform's SIMPLE_HISTORY_DATE_INDEX in test settings django-simple-history bakes the SIMPLE_HISTORY_DATE_INDEX setting's value into the db_index it generates for every HistoricalRecords() model's history_date field. This library's test settings never set it, so its committed migrations recorded db_index=True (the django-simple-history default) for CompetencyCriteriaGroup, CompetencyCriterion, and CompetencyRuleProfile's historical tables. openedx-platform, the primary consumer these models are built for, sets SIMPLE_HISTORY_DATE_INDEX = False globally in openedx/envs/common.py, so installing this library there makes the live model state disagree with the shipped migrations: Django detects a missing migration for history_date on every one of these three tables the moment openedx-platform's own test suite loads them, failing its MigrationTests.test_migrations_are_in_sync check. Sets the same value in test_settings.py so this library's own migrations match what its actual consumer produces, and adds the migration that `makemigrations` generates as a result. Co-Authored-By: Claude Sonnet 5 --- ...encycriteriagroup_history_date_and_more.py | 28 +++++++++++++++++++ test_settings.py | 7 +++++ 2 files changed, 35 insertions(+) create mode 100644 src/openedx_learning/migrations/0008_alter_historicalcompetencycriteriagroup_history_date_and_more.py diff --git a/src/openedx_learning/migrations/0008_alter_historicalcompetencycriteriagroup_history_date_and_more.py b/src/openedx_learning/migrations/0008_alter_historicalcompetencycriteriagroup_history_date_and_more.py new file mode 100644 index 000000000..ca1e5d3ca --- /dev/null +++ b/src/openedx_learning/migrations/0008_alter_historicalcompetencycriteriagroup_history_date_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 5.2.16 on 2026-10-07 12:20 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("openedx_learning", "0007_alter_criterion_override_help_text"), + ] + + operations = [ + migrations.AlterField( + model_name="historicalcompetencycriteriagroup", + name="history_date", + field=models.DateTimeField(), + ), + migrations.AlterField( + model_name="historicalcompetencycriterion", + name="history_date", + field=models.DateTimeField(), + ), + migrations.AlterField( + model_name="historicalcompetencyruleprofile", + name="history_date", + field=models.DateTimeField(), + ), + ] diff --git a/test_settings.py b/test_settings.py index b3cc99ec1..b31799db5 100644 --- a/test_settings.py +++ b/test_settings.py @@ -127,3 +127,10 @@ def root(*args): "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", ] + +# django-simple-history bakes this setting's value into the db_index it generates for every +# HistoricalRecords() model's history_date field, so a library that ships committed migrations +# must set it to whatever its actual consumer uses, or installing those migrations into that +# consumer's project drifts out of sync with its live model state. openedx-platform (this +# library's primary consumer) sets this to False in openedx/envs/common.py. +SIMPLE_HISTORY_DATE_INDEX = False From e77bb822d66a7fdde175449b94b7c04ef90a90a7 Mon Sep 17 00:00:00 2001 From: ufedaseyeuconsultant Date: Wed, 7 Oct 2026 22:47:23 +0300 Subject: [PATCH 2/4] fix: renumber migration past upstream's 0008, fix CourseRun import Rebasing onto upstream/main (not this fork's lagging origin/main) put this branch's own 0008 migration side by side with upstream's unrelated 0008_competency_mastery_status, 0009, and 0010 (all added after this branch forked), forking the migration graph since both chains depend on 0007. Deletes this branch's old 0008 and regenerates it via makemigrations so it lands as 0011, depending on 0010_studentcompetencystatus; its operations are otherwise identical to the deleted file. Also switches criteria.py's CourseRun import from openedx_catalog.models to openedx_catalog.models_api. openedx-platform's own import-linter config treats openedx_catalog as an isolated app, reachable only through its api/models_api/data/tests modules, so the direct .models import fails that check once openedx-platform installs this library, even though this repo's own, more permissive layering contract never caught it. models_api already re-exports CourseRun for exactly this kind of foreign-key reference; the FK still targets the same model, so no migration is needed for this part. Co-Authored-By: Claude Sonnet 5 --- src/openedx_learning/applets/cbe/models/criteria.py | 2 +- ...istoricalcompetencycriteriagroup_history_date_and_more.py} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/openedx_learning/migrations/{0008_alter_historicalcompetencycriteriagroup_history_date_and_more.py => 0011_alter_historicalcompetencycriteriagroup_history_date_and_more.py} (84%) diff --git a/src/openedx_learning/applets/cbe/models/criteria.py b/src/openedx_learning/applets/cbe/models/criteria.py index ea23196fc..084ae81f2 100644 --- a/src/openedx_learning/applets/cbe/models/criteria.py +++ b/src/openedx_learning/applets/cbe/models/criteria.py @@ -15,7 +15,7 @@ from organizations.models import Organization from simple_history.models import HistoricalRecords -from openedx_catalog.models import CourseRun +from openedx_catalog.models_api import CourseRun from openedx_django_lib.fields import case_insensitive_char_field, immutable_uuid_field from openedx_tagging.models import ObjectTag, Tag diff --git a/src/openedx_learning/migrations/0008_alter_historicalcompetencycriteriagroup_history_date_and_more.py b/src/openedx_learning/migrations/0011_alter_historicalcompetencycriteriagroup_history_date_and_more.py similarity index 84% rename from src/openedx_learning/migrations/0008_alter_historicalcompetencycriteriagroup_history_date_and_more.py rename to src/openedx_learning/migrations/0011_alter_historicalcompetencycriteriagroup_history_date_and_more.py index ca1e5d3ca..56c46c49b 100644 --- a/src/openedx_learning/migrations/0008_alter_historicalcompetencycriteriagroup_history_date_and_more.py +++ b/src/openedx_learning/migrations/0011_alter_historicalcompetencycriteriagroup_history_date_and_more.py @@ -1,4 +1,4 @@ -# Generated by Django 5.2.16 on 2026-10-07 12:20 +# Generated by Django 5.2.17 on 2026-10-07 19:39 from django.db import migrations, models @@ -6,7 +6,7 @@ class Migration(migrations.Migration): dependencies = [ - ("openedx_learning", "0007_alter_criterion_override_help_text"), + ("openedx_learning", "0010_studentcompetencystatus"), ] operations = [ From d87b203b397d607eed5379fa2dab5eb72b8e2955 Mon Sep 17 00:00:00 2001 From: ufedaseyeuconsultant Date: Fri, 9 Oct 2026 19:52:45 +0300 Subject: [PATCH 3/4] fix: set SIMPLE_HISTORY_DATE_INDEX in projects/dev.py, explain why manage.py defaults to projects.dev when DJANGO_SETTINGS_MODULE isn't set, and running makemigrations under it (the path a contributor is most likely to hit locally) regenerated the history_date index on all three CompetencyCriteria* historical tables, undoing this fix. projects/dev.py now sets the same value, pointing back at test_settings.py's comment instead of repeating it. Also replaces that comment with one that explains why openedx-platform chose False, not just the baking mechanism: it's been set since openedx-platform's 2023 django-simple-history upgrade (openedx/openedx-platform#32880), to avoid adding an index to every historical table in the platform at once. Co-Authored-By: Claude Sonnet 5 --- projects/dev.py | 3 +++ test_settings.py | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/projects/dev.py b/projects/dev.py index 02f5824e2..733077c36 100644 --- a/projects/dev.py +++ b/projects/dev.py @@ -112,6 +112,9 @@ USE_TZ = True +# See test_settings.py for why this must match openedx-platform. +SIMPLE_HISTORY_DATE_INDEX = False + # openedx-core required configuration OPENEDX_LEARNING = { # Custom file storage, though this is better done through Django's diff --git a/test_settings.py b/test_settings.py index b31799db5..4480c094b 100644 --- a/test_settings.py +++ b/test_settings.py @@ -128,9 +128,10 @@ def root(*args): "django.contrib.messages.middleware.MessageMiddleware", ] -# django-simple-history bakes this setting's value into the db_index it generates for every -# HistoricalRecords() model's history_date field, so a library that ships committed migrations -# must set it to whatever its actual consumer uses, or installing those migrations into that -# consumer's project drifts out of sync with its live model state. openedx-platform (this -# library's primary consumer) sets this to False in openedx/envs/common.py. +# django-simple-history bakes this setting into the history_date field of every +# HistoricalRecords() model, and therefore into any migration we generate for one. +# openedx-platform has had this set to False since its 2023 django-simple-history +# upgrade (openedx/openedx-platform#32880), to avoid adding an index to every +# historical table in the platform at once. Our migrations run there, so this has +# to match. SIMPLE_HISTORY_DATE_INDEX = False From f42e6b2d55478fc71517d7e898ff16b2b9dae863 Mon Sep 17 00:00:00 2001 From: ufedaseyeuconsultant Date: Fri, 9 Oct 2026 19:52:53 +0300 Subject: [PATCH 4/4] fix: renumber migration past upstream's new 0011 and 0012 Rebased onto upstream/main, which merged two more migrations (0011_studentcompetencycriterionstatus, 0012_studentcompetencycriteriagroupstatus) since this branch's migration was last renumbered, forking the graph again. Deletes the old 0011 and regenerates via makemigrations, landing as 0013 depending on 0012_studentcompetencycriteriagroupstatus; the field operations are otherwise identical to the deleted file. Co-Authored-By: Claude Sonnet 5 --- ...istoricalcompetencycriteriagroup_history_date_and_more.py} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/openedx_learning/migrations/{0011_alter_historicalcompetencycriteriagroup_history_date_and_more.py => 0013_alter_historicalcompetencycriteriagroup_history_date_and_more.py} (84%) diff --git a/src/openedx_learning/migrations/0011_alter_historicalcompetencycriteriagroup_history_date_and_more.py b/src/openedx_learning/migrations/0013_alter_historicalcompetencycriteriagroup_history_date_and_more.py similarity index 84% rename from src/openedx_learning/migrations/0011_alter_historicalcompetencycriteriagroup_history_date_and_more.py rename to src/openedx_learning/migrations/0013_alter_historicalcompetencycriteriagroup_history_date_and_more.py index 56c46c49b..3d14915e9 100644 --- a/src/openedx_learning/migrations/0011_alter_historicalcompetencycriteriagroup_history_date_and_more.py +++ b/src/openedx_learning/migrations/0013_alter_historicalcompetencycriteriagroup_history_date_and_more.py @@ -1,4 +1,4 @@ -# Generated by Django 5.2.17 on 2026-10-07 19:39 +# Generated by Django 5.2.17 on 2026-10-09 16:49 from django.db import migrations, models @@ -6,7 +6,7 @@ class Migration(migrations.Migration): dependencies = [ - ("openedx_learning", "0010_studentcompetencystatus"), + ("openedx_learning", "0012_studentcompetencycriteriagroupstatus"), ] operations = [