{"record":{"id":"b777bda37c8fd912","repo":"apache/beam","slug":"expected-split-of-source-r-at-fraction-r-after-reading-d","errorCode":null,"errorMessage":"Expected split of source %r at fraction %r after reading %d elements to fail. But splitting succeeded with result %r.","messagePattern":"Expected split of source %r at fraction %r after reading (.+?) elements to fail\\. But splitting succeeded with result %r\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/source_test_utils.py","lineNumber":335,"sourceCode":"          'Observed split fraction was %r.' % (split_result[1], ))\n\n  stop_position_after_split = range_tracker.stop_position()\n  if split_result and stop_position_after_split == stop_position_before_split:\n    raise ValueError(\n        'Stop position %r did not change after a successful '\n        'split of source %r at fraction %r.' %\n        (stop_position_before_split, source, split_fraction))\n\n  if expected_outcome == ExpectedSplitOutcome.MUST_SUCCEED_AND_BE_CONSISTENT:\n    if not split_result:\n      raise ValueError(\n          'Expected split of source %r at fraction %r to be '\n          'successful after reading %d elements. But '\n          'the split failed.' %\n          (source, split_fraction, num_items_to_read_before_split))\n  elif expected_outcome == ExpectedSplitOutcome.MUST_FAIL:\n    if split_result:\n      raise ValueError(\n          'Expected split of source %r at fraction %r after '\n          'reading %d elements to fail. But splitting '\n          'succeeded with result %r.' % (\n              source,\n              split_fraction,\n              num_items_to_read_before_split,\n              split_result))\n\n  elif (expected_outcome\n        != ExpectedSplitOutcome.MUST_BE_CONSISTENT_IF_SUCCEEDS):\n    raise ValueError('Unknown type of expected outcome: %r' % expected_outcome)\n  current_items.extend([value for value in reader_iter])\n\n  residual_range = (\n      split_result[0], stop_position_before_split) if split_result else None\n\n  return _verify_single_split_fraction_result(\n      source,","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/source_test_utils.py#L317-L353","documentation":"This ValueError is thrown by the Beam iobase source test harness when a test asserts that a source's split_at_fraction() must fail at a given fraction, but the split actually succeeded and returned a residual source. It flags a source whose dynamic work rebalancing behavior contradicts the expected outcome declared by the test.","triggerScenarios":"Calling assert_split_at_fraction_behavior or assert_split_at_fraction_binary with expected_outcome=ExpectedSplitOutcome.MUST_FAIL on a source whose split_at_fraction() returns a non-None (successful) result after reading num_items_to_read_before_split items.","commonSituations":"Writing or porting a custom iobase.BoundedSource/RangeTracker whose split_at_fraction implementation succeeds at fractions the test expects to fail; changing a RangeTracker's try_split logic after a version upgrade; copy-pasting MUST_FAIL from another test where the source semantics differed.","solutions":["Inspect the source's split_at_fraction/RangeTracker.try_split to see why it succeeds at that fraction and fix the source if success is incorrect.","Change expected_outcome to ExpectedSplitOutcome.MUST_BE_CONSISTENT_IF_SUCCEEDS if success is legitimate.","Pick a split fraction where the source is genuinely expected to refuse to split (e.g. fractions outside the remaining range).","Log the returned split_result to confirm which primary/residual ranges the split produced before deciding the expected outcome."],"exampleFix":"// before\nassert_split_at_fraction_behavior(source, ExpectedSplitOutcome.MUST_FAIL, 0.5, 3)\n// after\nassert_split_at_fraction_behavior(source, ExpectedSplitOutcome.MUST_BE_CONSISTENT_IF_SUCCEEDS, 0.5, 3)","handlingStrategy":"validation","validationCode":"from apache_beam.io.iobase import ExpectedSplitOutcome\nassert isinstance(expected_outcome, ExpectedSplitOutcome)\nassert expected_outcome == ExpectedSplitOutcome.MUST_FAIL\n# Optionally probe: result = source.split_at_fraction(fraction) and confirm it's None","typeGuard":"def is_valid_outcome(v):\n    return isinstance(v, ExpectedSplitOutcome)","tryCatchPattern":"try:\n    assert_split_at_fraction_behavior(source, ExpectedSplitOutcome.MUST_FAIL, fraction, n)\nexcept ValueError as e:\n    logging.error('Split behavior mismatch: %s', e)","preventionTips":["Derive expected outcomes from the RangeTracker's documented semantics, not guesswork","Run split assertions against OffsetRangeTracker first as a baseline","Log split_result before asserting so mismatches are diagnosable"],"tags":["python","apache-beam","iobase","source-testing","split-at-fraction"],"backgroundTag":"unexpected-response-shape","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}