kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Migrate LearnerLessonViewset to serializer-derived values pattern

Open rtibbles opened this issue 9 months ago • 3 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Overview

Migrate LearnerLessonViewset from explicit values/field_map to serializer-derived pattern as part of the BaseValuesViewset refactor (#14036).

Complexity: Medium Target branch: develop

Context

LearnerLessonViewset in kolibri/plugins/learn/viewsets.py has values (9 fields including 3 collection__* traversals), a field_map with "classroom" → _map_lesson_classroom, and a consolidate() that delegates to _consolidate_lessons_data. It has no serializer_class or annotate_queryset(). The viewset filters to lessons actively assigned to the requesting user.

The Change

Create a serializer for LearnerLessonViewset that defines all read-path fields including the nested classroom structure. Remove the explicit values tuple and field_map. The consolidate() method will remain for lesson resource data enrichment.

See #14036 for the overall pattern and FacilityUserViewSet in kolibri/core/auth/api.py for a concrete migration example.

Relocation

None in this issue: the learn plugin's viewsets.py cannot coexist with the viewsets/ package, so all learn moves happen together in #14310. Migrate in place.

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 _consolidate_lessons_data helper

  • Moving code into the viewsets/ package — all learn moves happen in #14310

Acceptance Criteria

  • [ ] Explicit values tuple and field_map removed from LearnerLessonViewset
  • [ ] Serializer defines all read-path fields including nested classroom
  • [ ] consolidate() continues to work correctly
  • [ ] Existing API tests pass unchanged
  • [ ] Benchmark comparison passes (data hash match + no performance regression)

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.learn.viewsets.LearnerLessonViewset \
        --inherit-kolibri-home -o baseline.json
    
    # ... make changes ...
    
    python integration_testing/scripts/viewset_serialization_benchmark.py \
        kolibri.plugins.learn.viewsets.LearnerLessonViewset \
        --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:

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: FacilityUserViewSet in kolibri/core/auth/api.py

AI usage

This issue was drafted with Claude Code assistance, reviewed and directed by @rtibbles.

rtibbles avatar Mar 02 '26 04:03 rtibbles

Watching for resolution on behalf of learningequality/kolibri#14310.

rtibblesbot avatar Jun 09 '26 15:06 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jun 12 '26 01:06 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jun 12 '26 05:06 rtibblesbot