Migrate AttemptLogViewSet 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 AttemptLogViewSet from explicit values tuple to serializer-derived pattern as part of the BaseValuesViewset refactor (#14036).
Complexity: Low Target branch: develop
Context
AttemptLogViewSet in kolibri/core/logger/api.py uses a module-level attemptlog_values tuple (16 fields) but has no serializer_class, field_map, consolidate(), or annotate_queryset(). A serializer will need to be created or an existing one updated to serve as the source of truth.
Note: attemptlog_values is also referenced by the diff action on MasteryLogViewSet — coordinate with that migration if needed.
The Change
Create or update a serializer for AttemptLogViewSet that defines all 16 read-path fields. Remove the explicit values tuple so that values are derived from the serializer.
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 AttemptLog domain into kolibri/core/logger/viewsets/attempt_log.py as a pure-move commit: the viewset(s), their serializers (inline above the viewsets), and any domain-specific filters and permission classes (AttemptFilter). 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.
This is the last issue touching kolibri/core/logger/api.py: also move the remaining non-migrating code into the package — ProgressTrackingViewSet (with LogContext, HexStringUUIDField, and the session serializers MasteryModelSerializer/StartSessionSerializer/InteractionSerializer/UpdateSessionSerializer), TotalContentProgressViewSet, GenerateCSVLogRequestViewSet (with its serializer and filter), and BaseLogFilter. Then delete api.py.
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
- Write-path changes — only the read serialization path is affected
Acceptance Criteria
-
[ ] Explicit
valuestuple removed fromAttemptLogViewSet -
[ ] Serializer has all read-path fields with correct
sourcekwargs -
[ ] Existing API tests pass unchanged
-
[ ] Benchmark comparison passes (data hash match + no performance regression)
-
[ ] The
attemptlog_valuesmodule-level constant is preserved — it is referenced by thediffaction onMasteryLogViewSetand will be cleaned up in #14294 -
[ ] The migrated domain lives in
kolibri/core/logger/viewsets/attempt_log.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
-
[ ] Remaining non-migrating code moved;
kolibri/core/logger/api.pydeleted
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.core.logger.api.AttemptLogViewSet \ --inherit-kolibri-home -o baseline.json # ... make changes ... python integration_testing/scripts/viewset_serialization_benchmark.py \ kolibri.core.logger.api.AttemptLogViewSet \ --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 and generate user data before benchmarking:
kolibri manage importchannel network 95a52b386f2c485cb97dd60901674a98
kolibri manage importcontent network 95a52b386f2c485cb97dd60901674a98
kolibri manage generateuserdata
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.core.logger.viewsets.attempt_log.AttemptLogViewSet).
Watching for resolution on behalf of learningequality/kolibri#14302.
Plan: Migrate AttemptLogViewSet from explicit values tuple to serializer-derived pattern, then relocate all kolibri/core/logger/api.py code into a viewsets/ package and delete api.py.
- [ ] Write tests for AttemptLogViewSet
- [ ] Set up data and capture baseline
- [ ] Add AttemptLogSerializer to api.py
- [ ] Update AttemptLogViewSet to use serializer_class
- [ ] Verify the migration with benchmark comparison
- [ ] Investigate git history before moving code
- [ ] Create viewsets/ package with filters.py and attempt_log.py
- [ ] Move MasteryLogViewSet to viewsets/mastery_log.py
- [ ] Move ProgressTrackingViewSet and TotalContentProgressViewSet
- [ ] Move GenerateCSVLogRequestViewSet; delete api.py
@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly
How was this generated?
- Implemented code following the pre-approved plan using test-driven development (red-green-refactor)
- Ran the project's full test suite and linter before committing
- For UI changes: captured live screenshots to verify rendering
- For backend changes: verified with example API/CLI output
PR submitted: learningequality/kolibri#14834
Status: Draft — CI running, benchmark comparison pending manual verification.
Note on rebase: This branch was rebased onto develop after #14294 merged. The MasteryLog code in this PR incorporates #14294's changes. One fix was needed: MasteryLogViewSet.diff previously accessed AttemptLogViewSet.values (the explicit tuple); after migrating AttemptLogViewSet to serializer-derived, this became AttemptLogViewSet._ensure_initialized(); AttemptLogViewSet._values to trigger the lazy initialization.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.