GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix exercise extra_fields migration for non-m_of_n mastery models by rtibbles · Pull Request #5714 · learningequality/studio

Conversation

@rtibbles

@rtibbles rtibbles commented Feb 20, 2026

Copy link
Copy Markdown
Member

Summary

migrate_extra_fields was carrying over non-null m/n values for non-m_of_n mastery models (e.g. do_all, num_correct_in_a_row). The mastery criteria JSON schema requires m and n to be null for these models, causing frontend AJV validation to fail and exercises to appear incomplete — even though backend mark_complete passed them (it skips schema validation for old-style data).

Fixing just the m/n nulling in migrate_extra_fields would have been sufficient to resolve the immediate bug. However, to avoid having to worry about old-style exercise data ever again, this PR also:

  • Fixes the ricecooker import path (create_node) to run migrate_extra_fields on incoming exercise data before writing to DB
  • Adds a management command fix_exercise_extra_fields to repair existing data in production — both already-migrated exercises with invalid m/n and any remaining old-style exercises that haven't been migrated yet

Verification: all new and existing tests pass (test_contentnodes.py, test_views_internal.py).

References

Fixes #5667

Reviewer guidance

  • utils/nodes.py:528-530 — the core fix: 3 lines that null out m/n for non-m_of_n models. This runs on every exercise API read/write via consolidate_extra_fields and ExtraFieldsSerializer.update, so correctness here is critical. Only m_of_n should preserve m/n values; all other mastery models should have them set to null.
  • views/internal.py:839-842 — adding migrate_extra_fields to the ricecooker import path. This runs before the existing completion_criteria.validate() block, so newly-migrated data gets validated too. Test coverage confirms new-style extra_fields pass through unchanged.
  • Management command — iterates all exercises using iterator() with Python-side filtering to avoid expensive nested JSON queries. Individual save(update_fields=...) per affected node. Safe for large datasets but will be slow on production (millions of exercises). Run with --dry-run first to verify counts.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
rtibbles and others added 2 commits February 19, 2026 16:34
@rtibbles @claude
Fix migrate_extra_fields to null m/n for non-m_of_n mastery models
a5129f9
Old-style exercise extra_fields were being migrated with non-null m/n
values for non-m_of_n mastery models (e.g. do_all, num_correct_in_a_row).
The mastery criteria JSON schema requires m and n to be null for these
models, causing frontend AJV validation to fail and exercises to appear
incomplete.

- Fix migrate_extra_fields to set m/n to null for non-m_of_n models
- Add management command fix_exercise_extra_fields to repair existing
  data in production

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@rtibbles @claude
Migrate old-style exercise extra_fields on ricecooker import
7cf6353
The ricecooker import path (create_node) was writing old-style
extra_fields directly to the DB without running migration. This
ensures incoming exercise data is migrated to the new-style
options.completion_criteria format before being persisted.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
rtibbles
rtibbles commented Feb 20, 2026
View reviewed changes
Comment thread contentcuration/contentcuration/utils/nodes.py
not extra_fields.get("options", {}).get("completion_criteria", {})
and mastery_model is not None
):
if mastery_model != exercises.M_OF_N:

@rtibbles rtibbles Feb 20, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This is the core of the fix, really - m and n should be None if we don't have an exercises.M_OF_N mastery model.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bjester reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
bjester
bjester reviewed Feb 20, 2026
View reviewed changes
Comment thread contentcuration/contentcuration/management/commands/fix_exercise_extra_fields.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread contentcuration/contentcuration/management/commands/fix_exercise_extra_fields.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread contentcuration/contentcuration/management/commands/fix_exercise_extra_fields.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread contentcuration/contentcuration/management/commands/fix_exercise_extra_fields.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@rtibbles
Cleanup management command and add more logging.
3be47f3
@rtibbles

rtibbles commented Feb 20, 2026

Copy link
Copy Markdown
Member Author

Updated!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bjester
bjester reviewed Feb 20, 2026
View reviewed changes
Comment thread contentcuration/contentcuration/management/commands/fix_exercise_extra_fields.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

rtibbles added 3 commits February 20, 2026 09:18
@rtibbles
Target dry_run more focally for better info, cleanup redundant save.
40ba158
@rtibbles
Lazy loading, lazy coding.
946fa2b
@rtibbles
Mark_complete returns an empty list if complete.
ddd9a71
bjester
bjester approved these changes Feb 20, 2026
View reviewed changes

@bjester bjester left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM! Tests have good coverage over critical logic. Dry run logic and command logging makes sense

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@rtibbles
rtibbles merged commit c7120d5 into learningequality:hotfixes Feb 20, 2026
13 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@rtibbles
rtibbles deleted the exercise_your_rights branch February 20, 2026 17:51
@rtibbles rtibbles mentioned this pull request Mar 17, 2026
Exercises are being marked as 'Incomplete' for no obvious reason #5667
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@bjester bjester bjester approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@rtibbles @bjester
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.