fix: _truncate_array under-reports truncated flag after dropping/shortening elements#37242
Open
1795771535y-cell wants to merge 1 commit into
Open
Conversation
…tening elements When _truncate_array breaks due to size limit exceeding target_size, the truncated flag was not set to True, causing dropped tail elements to go unreported. Additionally, the flag was overwritten (truncated = part_result.truncated) instead of accumulated, so a later fitting element could reset a previously-set flag to False. Fix by setting truncated = True before the size-limit break, and using logical OR to accumulate (truncated = truncated or part_result.truncated). Fixes langgenius#37192 Signed-off-by: C4P-T <cap@teamos.dev>
Contributor
Pyrefly Type Coverage
|
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 #37192
_truncate_array\ has two bugs causing the \ runcated\ flag to be under-reported:
Changes
Testing
Verified with the reproduction cases from #37192:
\\python
t = VariableTruncator(array_element_limit=20, max_size_bytes=1000)
r = t._truncate_array([10, 20, 30, 40, 50], 12)
Before: r.truncated == False, r.value == [10, 20, 30, 40]
After: r.truncated == True ✅
t2 = VariableTruncator(array_element_limit=20, max_size_bytes=1000, string_length_limit=10)
r2 = t2._truncate_array(['x'*60, 'a'], 60)
Before: r2.truncated == False
After: r2.truncated == True ✅
\\
Also verified element-count-limit path and no-truncation path are unaffected.