Skip to content

Migrate PinnedDeviceViewSet to serializer-derived values pattern #14292

@rtibbles

Description

@rtibbles

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

Overview

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

Complexity: Low
Target branch: develop

Context

PinnedDeviceViewSet in kolibri/core/discovery/api.py currently has both serializer_class = PinnedDeviceSerializer and an explicit values = ("instance_id", "id") tuple. It has no field_map, consolidate(), or annotate_queryset() — making it a straightforward migration.

The Change

Remove the explicit values tuple from PinnedDeviceViewSet so that values and field mappings are derived from PinnedDeviceSerializer. Update the serializer if any read-path fields are missing or need source kwargs.

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

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 values tuple removed from PinnedDeviceViewSet
  • PinnedDeviceSerializer has all read-path fields with correct source kwargs
  • 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.core.discovery.api.PinnedDeviceViewSet \
        --inherit-kolibri-home -o baseline.json
    
    # ... make changes ...
    
    python integration_testing/scripts/viewset_serialization_benchmark.py \
        kolibri.core.discovery.api.PinnedDeviceViewSet \
        --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 (run via kolibri manage shell before benchmarking):

from kolibri.core.discovery.models import PinnedDevice
import uuid

for i in range(100):
    PinnedDevice.objects.get_or_create(
        instance_id=uuid.uuid4(),
    )

References

AI usage

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

Metadata

Metadata

Assignees

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions