Gate DEBUG output validation to serializer-derived viewsets#14811
Open
rtibbles wants to merge 1 commit into
Open
Gate DEBUG output validation to serializer-derived viewsets#14811rtibbles wants to merge 1 commit into
rtibbles wants to merge 1 commit into
Conversation
Legacy explicit-values viewsets often pair a write-oriented serializer_class with a different read shape, so validating their serialized output against the serializer raised spurious ValueErrors (500s) in dev mode. Track whether a class derives its values from its serializer and only build/apply the DEBUG validation schema when it does. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Build Artifacts
Smoke test screenshot |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The DEBUG-mode output validator in
ValuesViewset.serialize()ran against every viewset. Legacy viewsets that pair an explicitvaluestuple with a write-orientedserializer_classwere validated against the wrong contract, so they 500ed in dev mode. Validation is now gated to viewsets whose values are derived from their serializer; legacy explicit-values viewsets skip it.References
Follow-up to #14327, which introduced the DEBUG-mode output validation.
Reviewer guidance
To reproduce: on develop, run the dev server and request any endpoint backed by a legacy viewset that defines both
valuesandserializer_class(e.g./api/lessons/lesson/) — it 500s with aValueErrorabout missing/unexpected fields. On this branch the same request succeeds.The existing drift tests in
TestDevModeSafeguardscover that serializer-derived viewsets are still validated.AI usage
Implemented with Claude Code: it diagnosed the root cause, wrote failing tests reproducing the dev-mode 500 before the fix, and applied the gate. I reviewed the full diff before pushing.
🤖 Generated with Claude Code