The team has a small Python module for aggregating report rows into buckets and preparing a short preview. After a recent PR, the behavior became unstable: repeated calls sometimes depend on each other, and the preview may not match the actually processed data when working with a one-shot input.
You need to review the diff and find exactly two independent defective changes in the post-change version.
Behavior requirements:
build_bucket_report(rows, *, preview_limit=3) -> dict[str, object], where rows is an iterable source of strings in the format "bucket:value";: must be ignored;counts field must contain the number of elements in each bucket;preview field must contain no more than preview_limit first valid records as "bucket=value" strings;Reproduction steps:
from report_builder import build_bucket_reportrows = iter(["a:1", "b:2", "a:3"])print(build_bucket_report(rows, preview_limit=2))print(build_bucket_report(["x:1"]))print(build_bucket_report(["y:2"]))Assumptions:
: do not participate in counting, but they validate the record as complete;preview must match the original order of valid strings;CPython 3.12.4, standard library only. Verification assumes a local run of the module as ordinary Python code without pytest and without third-party packages.
Use line comments to explain the problem, its impact, the fix and how to test it.