From 71a79fec0a2f2536bd81b01175460d21a007e43d Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Wed, 1 Apr 2026 12:51:14 -0400 Subject: [PATCH] fix: Make container_type backfill reversible This is trivial and will be helpful for devs who need to move back and forth across this migrations step for whatever reason (switching branches, resolving DB issues). Bump patch version to 0.38.1 --- .../migrations/0005_containertypes.py | 13 ++++++++++++- src/openedx_core/__init__.py | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/openedx_content/migrations/0005_containertypes.py b/src/openedx_content/migrations/0005_containertypes.py index 65250188a..ad9ceed51 100644 --- a/src/openedx_content/migrations/0005_containertypes.py +++ b/src/openedx_content/migrations/0005_containertypes.py @@ -29,6 +29,14 @@ def backfill_container_types(apps, schema_editor): raise ValueError(f"container {unknown_containers[0]} is of unknown container type. Cannot apply migration.") +def clear_container_types(apps, schema_editor): + """ + Drop the contents of the container_type field for the reverse migration. + """ + Container = apps.get_model("openedx_content", "Container") + Container.objects.update(container_type=None) + + class Migration(migrations.Migration): dependencies = [ ("openedx_content", "0004_componenttype_constraint"), @@ -68,7 +76,10 @@ class Migration(migrations.Migration): ), ), # 3. Populate the container_type column, which is currently NULL for all existing containers - migrations.RunPython(backfill_container_types), + migrations.RunPython( + code=backfill_container_types, + reverse_code=clear_container_types, + ), # 4. disallow NULL values from now on migrations.AlterField( model_name="container", diff --git a/src/openedx_core/__init__.py b/src/openedx_core/__init__.py index 03fd9fd50..2d323bdeb 100644 --- a/src/openedx_core/__init__.py +++ b/src/openedx_core/__init__.py @@ -6,4 +6,4 @@ """ # The version for the entire repository -__version__ = "0.38.0" +__version__ = "0.38.1"