DEV: Ensure that Serializers forward their scopes, now and forever #32984
+308
−138
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.
This commit is based on the premise that every serializer should have a
scope
parameter which is an instance of aGuardian
.In many places, serializers which construct other serializers neglect to forward their
scope
parameter to the sub-serializer. When one of these sub-serializers is later modified to make use of its scope in a new way or under a new circumstance, the missing scope along certain code paths can cause failures which are hard to debug. It is difficult to pin down where, within a chain of serializers, the scope has not been forwarded.This commit fixes all the current call-sites (in code with test coverage), where a serializer has neglected to forward its scope. It also introduces a mechanism to track where other classes fail to provide a scope when constructing a serializer. This mechanism will cause the codebase to evolve to a state where all serializers are reliably and predictably provided with a
Guardian
as their scope.Elements of this commit:
Modify
ApplicationSerializer#new
to log/raise an error if a serializer is constructed without ascope:
argument. (Error is raised only in a test environment.)Add a
scope: scope
argument to every call-site where a serializer is constructed by another serializer (forwarding sites) and thescope:
argument is missing.Define
PlaceholderGuardian
, to be used to provide ascope:
argument wherever one was missing in a non-forwarding serializer construction.Add a new
scope: PlaceholderGuardian.new
argument to every remaining (non-forwarding) call-site where a serializer is constructed without ascope:
argument. (Call-sites which already have ascope:
argument have been left untouched, even if it assigned thescope
tonil
.)