Remove legacy values/field_map code paths from BaseValuesViewset
❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.
Overview
With every viewset migrated, remove the legacy explicit values/field_map code paths so serializer_class is the only supported way to define a viewset's serialization contract.
Complexity: Medium Target branch: develop
Context
BaseValuesViewset._do_initialize (kolibri/core/api.py:258) branches on whether the class declares a values tuple, building the engine from the legacy explicit path or from the serializer. Every legacy site carries a TODO(#14302).
The Change
Remove from kolibri/core/api.py:
- The
has_explicit_valuesbranch in_do_initialize(api.py:259-265), leaving serializer derivation as the only path — a class with noserializer_classthen raises at init. generate_serializer()(api.py:294) and its caching inget_serializer_class()(api.py:337-348) — it exists only to synthesise a serializer for viewsets that declarevalues/field_mapinstead of one.
Remove from kolibri/core/utils/values_viewset/:
ValuesEngine.from_explicit(engine.py:228)normalize_field_map(field_map.py:375)_LegacyFieldMap(field_map.py:337) — the mutate-in-placemap_rowpath that passes unclaimed rawvalues()keys through to output_LegacyCallableFieldEntry(field_map.py:133)
Then expose values as a read-only property on the viewset, returning the engine's tuple. Doing this earlier would collide with viewsets that still declare their own tuple. ExamViewset (exams/viewsets/exam.py:470) and MasteryLogViewSet (logger/viewsets/mastery_log.py:94) read that property instead of _engine.values.
The two viewsets left without a serializer
Both inherit BaseValuesViewset but never call serialize(), so they have no serializer and would raise at init once the legacy branch goes. Neither can simply have its values tuple deleted:
ContentNodeProgressViewset(moved tocontent/viewsets/contentnode/progress.pyby #14300) uses itsvaluestuple —generate_response()applies it with.values(*self.values)to aContentSummaryLogqueryset, not to the viewset's ownContentNodequeryset. Aserializer_classwould therefore describe the wrong model. DropBaseValuesViewsetfrom its bases (TreeQueryMixin,GenericViewSet,ListModelMixinare all it needs — the pagination classes do not touch the engine) and replace the class attribute with a module-level tuple thatgenerate_response()reads.NetworkLocationFacilitiesView(discovery/viewsets/network_location.py:173) has a genuinely deadvaluestuple: it overridesretrieve()and builds theResponseby hand from_RemoteFacilitySerializer. Drop the tuple andBaseValuesViewsetwith it, inheritingGenericViewSet.
Both then need a serializer_class for DRF schema generation, which generate_serializer() used to supply — a bare Serializer stub, as ImportMetadataViewset already does (content/public_api.py:27).
RemoteViewSet (moved to content/viewsets/remote.py by #14306) is an abstract base that is never instantiated directly; confirm it carries no values/field_map and needs no stub.
Documentation and tests
docs/backend_architecture/api_patterns.rst: delete the "Migrating from Explicit Values" and "Explicit Values (Legacy)" sections, and the best-practice bullet that contrastssourcewithfield_map(:369).kolibri/core/test/test_api.py: deleteTestLegacyViewset(:2045), and convert the explicit-valuesviewsets used for convenience inTestDevModeSafeguards(:2423,:2436,:2547) toserializer_class.
Out of Scope
- Changes to the API response shape of any endpoint
- Changes to
annotate_queryset(),consolidate()ordeferred_fieldsbehavior
Acceptance Criteria
- [ ] All migration issues under this refactor are closed (this issue is blocked by them)
- [ ] Legacy
values/field_mapbranch andgenerate_serializer()removed fromkolibri/core/api.py - [ ]
ValuesEngine.from_explicit,normalize_field_map,_LegacyFieldMapand_LegacyCallableFieldEntryremoved - [ ]
valuesexposed as a read-only property, read byExamViewsetandMasteryLogViewSetin place of_engine.values - [ ]
ContentNodeProgressViewsetno longer inheritsBaseValuesViewset, and reads its column list from a module-level tuple - [ ]
NetworkLocationFacilitiesViewno longer inheritsBaseValuesViewset, and its deadvaluestuple is gone - [ ] Both carry a
serializer_classstub for schema generation;RemoteViewSetconfirmed to need none - [ ]
serializer_classis the only supported pattern; noTODO(#14302)markers remain - [ ] Legacy sections removed from
docs/backend_architecture/api_patterns.rst - [ ]
TestLegacyViewsetdeleted and theTestDevModeSafeguardsfixtures converted - [ ] All existing API tests pass unchanged
References
- Pattern documentation:
docs/backend_architecture/api_patterns.rst BaseValuesViewset:kolibri/core/api.py- Legacy engine surface:
kolibri/core/utils/values_viewset/engine.py,field_map.py - Unit tests:
kolibri/core/test/test_api.py
AI usage
This issue was drafted with Claude Code assistance, reviewed and directed by @rtibbles.
Plan: Make serializer_class the only supported way to define a viewset's serialization contract, deleting the explicit values/field_map engine path and everything that exists to support it.
- [x] Take
ContentNodeProgressViewsetoffBaseValuesViewset - [x] Take
NetworkLocationFacilitiesViewoffBaseValuesViewset - [x] Expose
valuesas a read-only viewset property - [x] Re-express the benchmark's explicit arms as serializer-derived
- [x] Re-express the two legacy test fixtures whose behaviour is not legacy
- [x] Delete the legacy explicit
values/field_mappath - [x] Self-review the produced code
@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