Migrate ClassroomNotificationsViewset to serializer-derived values pattern
❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.
Overview
Migrate ClassroomNotificationsViewset from explicit values/field_map to serializer-derived pattern as part of the BaseValuesViewset refactor (#14036).
Complexity: Medium Target branch: develop
Context
ClassroomNotificationsViewset in kolibri/plugins/coach/api.py has values (13 fields) and a field_map that renames notification_object → object and notification_event → event (to avoid reserved words). It has no serializer_class or consolidate(). The annotate_queryset() applies ordering and optional limit slicing.
The viewset uses a dedicated NOTIFICATIONS SQLite database connection with try/except OperationalError/DatabaseError fallback in filter_queryset and list — the list method also logs coach activity. The get_queryset returns the manager without .all().
The Change
Create a serializer for ClassroomNotificationsViewset that defines all read-path fields with the rename handling (notification_object → object, notification_event → event). Remove the explicit values tuple and field_map. The notifications DB error handling and coach activity logging remain unchanged.
See #14036 for the overall pattern and FacilityUserViewSet in kolibri/core/auth/api.py for a concrete migration example.
Relocation
After the migration commits, extract the ClassroomNotifications domain into kolibri/plugins/coach/viewsets/classroom_notifications.py as a pure-move commit: the viewset(s), their serializers (inline above the viewsets), and any domain-specific filters and permission classes (ClassroomNotificationsFilter, ClassroomNotificationsPermissions). Update imports (api_urls.py, tests, cross-references).
Moving code breaks GitHub blame (local git blame -C -C still works), so digest the history the move obscures:
- Run blame over the code being moved; flag hunks whose purpose isn't evident from the code or tests (odd guards, magic orderings, special cases).
- Chase each flagged hunk to its originating PR/issue; where the rationale is non-obvious and load-bearing, carry it forward as a code comment citing the reference.
- Where the rationale turns out to be obsolete, remove the code as part of the migration commits rather than annotating it.
Out of Scope
-
Changes to the API response shape — the API contract must not change
-
Modifications to existing tests — if tests need to change, the migration is wrong
-
Changes to the notifications DB error handling or coach activity logging
-
Moving the rest of the coach plugin's API code and deleting its old modules — that happens in #14819
Acceptance Criteria
-
[ ] Explicit
valuestuple andfield_mapremoved fromClassroomNotificationsViewset -
[ ] Serializer defines all read-path fields with correct renames for
objectandevent -
[ ] Notifications DB error handling unaffected
-
[ ] Existing API tests pass unchanged
-
[ ] Benchmark comparison passes (data hash match + no performance regression)
-
[ ] The migrated domain lives in
kolibri/plugins/coach/viewsets/classroom_notifications.py, moved as a pure-move commit separate from import updates -
[ ] Comments citing the originating PR/issue added where blame digestion found non-obvious, load-bearing rationale
Testing
- Before migrating: verify that existing test coverage is adequate. If the viewset has insufficient API tests, write them first to capture the current behavior. Tests must pass before and after migration without modification.
- Benchmark: run the benchmark script before and after the migration using the same data:
python integration_testing/scripts/viewset_serialization_benchmark.py \ kolibri.plugins.coach.api.ClassroomNotificationsViewset \ --inherit-kolibri-home -o baseline.json # ... make changes ... python integration_testing/scripts/viewset_serialization_benchmark.py \ kolibri.plugins.coach.api.ClassroomNotificationsViewset \ --inherit-kolibri-home --compare baseline.json - The benchmark comparison must pass — this validates that the data output is identical and there is no performance regression.
- Include the benchmark before/after comparison in the pull request description.
Benchmark data setup: import the Kolibri QA channel, generate user data, and interact with the system to create notifications:
kolibri manage importchannel network 95a52b386f2c485cb97dd60901674a98
kolibri manage importcontent network 95a52b386f2c485cb97dd60901674a98
kolibri manage generateuserdata
Notifications are created automatically by learner activity (completing exercises, quizzes, etc.). Use --inherit-kolibri-home with a KOLIBRI_HOME that has existing notification data.
References
- Tracking issue: #14036
- Benchmark script:
integration_testing/scripts/viewset_serialization_benchmark.py - Example migration:
FacilityUserViewSetinkolibri/core/auth/api.py
AI usage
This issue was drafted with Claude Code assistance, reviewed and directed by @rtibbles.
- After the move, the benchmark comparison run uses the new dotted path (e.g.
kolibri.plugins.coach.viewsets.classroom_notifications.ClassroomNotificationsViewset).
Watching for resolution on behalf of learningequality/kolibri#14819.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
Fixed in #14838