Allow cross-dataset-authored quizzes and lessons to sync#14765
Draft
rtibbles wants to merge 2 commits into
Draft
Allow cross-dataset-authored quizzes and lessons to sync#14765rtibbles wants to merge 2 commits into
rtibbles wants to merge 2 commits into
Conversation
Move the repeated "require an author FK, allow null only during deserialization, and drop references to a cross-dataset superuser" logic out of the course models and into AbstractFacilityDataModel.enforce_authoring_user_field, routing CourseSession, CourseSessionAssignment and UnitTestAssignment through it. No behaviour change: enforcement still happens on every non-deserialization save, matching the semantics established in learningequality#14130. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
Build Artifacts
Smoke test screenshot |
Exam, Lesson and their assignments declared their author foreign key null=True but blank=False, and required a creator in pre_save on add. When a record authored by a superuser from a different dataset (whose author FK is nulled by pre_save) was deserialized on a receiving device, clean_fields rejected the null (blank=False) and the pre_save add-check fired, leaving the record dirty in the Store and absent from the device. Make the author foreign keys blank=True and route the pre_save checks through enforce_authoring_user_field, which permits a null author during deserialization. The helper gates the required-author check on _state.adding so it fires only on local creation: a record that synced in with a null author (its cross-dataset superuser dropped) is then editable locally rather than raising IntegrityError on every PATCH. AttendanceSession had the same pre_save gap and is fixed too. Adds a serialize/deserialize regression test covering all three, a pre_save test that a null author survives a later update, and a lesson API test for PATCH of a null-created_by lesson. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
91ca5b3 to
62bbf33
Compare
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


Summary
pre_savenulls the author FK, but it'sblank=False, so deserialization rejects the null and the record stays dirty.blank=True, and skippre_saveenforcement during deserialization.AbstractFacilityDataModel.enforce_authoring_user_field. Fixes the same latent gap inAttendanceSession.References
pre_savesemantics from Align course model pre_save logic with awareness of deserialization #14130, extending the same pattern to exams, lessons and attendance.Reviewer guidance
AI usage
blank-vs-nullreasoning (verified against Django's validation path) and confirming the consolidation preserved thepre_savesemantics from Align course model pre_save logic with awareness of deserialization #14130.