{"record":{"id":"9d0eae9001ac6788","repo":"apache/beam","slug":"source-is-too-trivial-since-it-produces-only-d-values-please","errorCode":null,"errorMessage":"Source is too trivial since it produces only %d values. Please give a source that reads at least 2 values.","messagePattern":"Source is too trivial since it produces only (.+?) values\\. Please give a source that reads at least 2 values\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/source_test_utils.py","lineNumber":209,"sourceCode":"    source_info (Tuple[~apache_beam.io.iobase.BoundedSource, int, int]):\n      a three-tuple that gives the reference\n      :class:`~apache_beam.io.iobase.BoundedSource`, position to start reading\n      at, and a position to stop reading at.\n\n  Raises:\n    ValueError: if source is too trivial or reentrant read result\n      in an incorrect read.\n  \"\"\"\n\n  source, start_position, stop_position = source_info\n  assert isinstance(source, iobase.BoundedSource)\n\n  expected_values = [\n      val for val in source.read(\n          source.get_range_tracker(start_position, stop_position))\n  ]\n  if len(expected_values) < 2:\n    raise ValueError(\n        'Source is too trivial since it produces only %d '\n        'values. Please give a source that reads at least 2 '\n        'values.' % len(expected_values))\n\n  for i in range(1, len(expected_values) - 1):\n    read_iter = source.read(\n        source.get_range_tracker(start_position, stop_position))\n    original_read = []\n    for _ in range(i):\n      original_read.append(next(read_iter))\n\n    # Reentrant read\n    reentrant_read = [\n        val for val in source.read(\n            source.get_range_tracker(start_position, stop_position))\n    ]\n\n    # Continuing original read.","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/source_test_utils.py#L191-L227","documentation":"Raised by assert_reentrant_reads_succeed when the supplied BoundedSource produces fewer than 2 values over the given [start_position, stop_position) range. The reentrancy test needs at least 2 records so it can interrupt a read partway, perform a second (reentrant) read, and verify both reads are correct; a trivial source cannot exercise this. It is a precondition failure on the test input, not a bug in the source's read logic.","triggerScenarios":"Calling assert_reentrant_reads_succeed((source, start_position, stop_position)) where a full read of the source over that range yields 0 or 1 values.","commonSituations":"Testing with a tiny fixture file or a narrow position range in a unit test, so the source naturally produces a single record over the selected range.","solutions":["Provide a source/fixture that produces at least 2 records for the given range.","Widen the [start_position, stop_position) range passed in source_info so it spans multiple records.","Skip reentrancy testing for genuinely single-record sources and use a larger test input instead."],"exampleFix":"// before\nassert_reentrant_reads_succeed((src, 0, 1))\n// after\nassert_reentrant_reads_succeed((src, 0, src.estimate_size()))","handlingStrategy":"validation","validationCode":"vals = list(source.read(source.get_range_tracker(start, stop)))\nif len(vals) < 2:\n    pytest.skip(\"source trivial over this range; enlarge range or fixture\")","typeGuard":"def is_testable_range(source, start, stop):\n    return len(list(source.read(source.get_range_tracker(start, stop)))) >= 2","tryCatchPattern":"try:\n    source_test_utils.assert_reentrant_reads_succeed((src, start, stop))\nexcept ValueError as e:\n    if \"too trivial\" in str(e):\n        pytest.skip(str(e))\n    raise","preventionTips":["Use fixtures with several records for reentrancy tests","Pass a range covering the full source, not a single-record slice","Skip reentrancy checks for single-record sources deliberately"],"tags":["apache-beam","bounded-source","test-input","reentrant-read"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}