Repository navigation
Report a nested Array scope that got no Array under its own name only - #3099
Merged
Merged
Conversation
An Array scope inside an Array scope is read from each element of the
outer Array. When an element left that param out, or held something
other than an Array there, such as `0`, AttributesIterator yielded the
value as an element of the inner Array. The inner scope's validators
then reported a second error, named with the outer element's index for
the inner Array and a stale index for the outer one:
requires :points, type: Array do
requires :location, type: Array do
requires :id, type: Integer
end
end
{"points": [{"location": [{"id": 1}]},
{"location": [{"id": 1}, {"id": 2}]},
{"location": 0}]}
Before: points[2][location] is invalid,
points[1][location][2][id] is missing,
points[1][location][2][id] is invalid
After: points[2][location] is invalid
The iterator now passes over such a value, as #each already does at
the top for an Array scope that did not get an Array. The scope's own
validators still report it, so these requests answer 400 as before,
with the errors the same scope gives at the root. Five specs had pinned
the extra error and are updated.
Fixes #1998.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ericproulx
force-pushed
the
fix/scalar-for-nested-array-scope
branch
from
November 21, 2026 18:05
e14fc46 to
1a3685f
Compare
1 of 2 tasks
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
Fixes #1998.
An Array scope inside an Array scope is read from each element of the outer Array. When an element left that param out, or held something other than an Array there,
AttributesIteratoryielded the value as an element of the inner Array. The inner scope's validators then reported a second error, named with the outer element's index for the inner Array and a stale index for the outer one:{"points": [{"location": [{"id": 1}]}, {"location": [{"id": 1}, {"id": 2}]}, {"location": 0}]}points[2][location] is invalid, points[1][location][2][id] is missing, points[1][location][2][id] is invalidpoints[2][location] is invalid{"points": [{"location": [{"id": 1}, {"id": 2}]}, {}]}points[1][location] is missing, points[0][location][1][id] is missingpoints[1][location] is missingThe iterator now passes over such a value, as
#eachalready does at the top for an Array scope that did not get an Array. The scope's own validators still report it, so these requests answer 400 as before, with the errors the same scope gives at the root (subitems is missing,subitems is invalid).The reports in #1998 for well-formed input already had the right indices on master. This was the case left over, from the issue's
{ location: 0 }element.Specs
Five specs in
validations_spec.rbhad pinned the extra error, for examplechildren[1][parents] is missing, children[0][parents][1][name] is missing, children[0][parents][1][name] is emptyfor aparentsleft out ofchildren[1]. They now expect the scope's own error alone. Two new specs cover the issue's shape and fail without the change.Test plan
bundle exec rakepasses locally (RuboCop clean, 3342 examples, 0 failures).🤖 Generated with Claude Code