{"record":{"id":"ac6089fd7e6b295b","repo":"apache/beam","slug":"failed-assert-pcol-is-empty","errorCode":null,"errorMessage":"Failed assert: pcol is empty","messagePattern":"Failed assert: pcol is empty","errorType":"exception","errorClass":"BeamAssertException","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/testing/util.py","lineNumber":312,"sourceCode":"def is_empty():\n  def _empty(actual):\n    actual = list(actual)\n    if actual:\n      raise BeamAssertException('Failed assert: [] == %r' % actual)\n\n  return _empty\n\n\ndef is_not_empty():\n  \"\"\"\n  This is test method which makes sure that the pcol is not empty and it has\n  some data in it.\n  :return:\n  \"\"\"\n  def _not_empty(actual):\n    actual = list(actual)\n    if not actual:\n      raise BeamAssertException('Failed assert: pcol is empty')\n\n  return _not_empty\n\n\ndef assert_that(\n    actual,\n    matcher,\n    label='assert_that',\n    reify_windows=False,\n    use_global_window=True):\n  \"\"\"A PTransform that checks a PCollection has an expected value.\n\n  Note that assert_that should be used only for testing pipelines since the\n  check relies on materializing the entire PCollection being checked.\n\n  Args:\n    actual: A PCollection.\n    matcher: A matcher function taking as argument the actual value of a","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/testing/util.py#L294-L330","documentation":"BeamAssertException raised by the `_not_empty` matcher returned by `assert_that(..., equal_to)`-style helpers when the pipeline's output PCollection is completely empty. Beam throws it because a caller asked to assert that the PCollection has data but the transform produced nothing, so the assertion (or a check for non-emptiness) failed at runtime during pipeline evaluation.","triggerScenarios":"Calling `assert_that(pcoll, _not_empty)` (directly or via equal_to-style matchers) on a PCollection whose evaluation yields zero elements — e.g. a filter/par-do upstream eliminated all records, or the source produced no data.","commonSituations":"Test pipelines where an upstream `Filter` removed everything, reading from an empty file/table/topic, a side-input or window that produced no elements, or a mistaken filter predicate in test code.","solutions":["Inspect the upstream transforms and source: relax the filter predicate or fix the source so at least one element is produced.","If emptiness is expected/acceptable, remove the non-emptiness assert or assert on the empty result explicitly instead.","Add logging/counting of input and output elements to find where records are dropped."],"exampleFix":"// before\nassert_that(result, _not_empty, label='nonempty')\n// after\n# only assert if data is guaranteed; otherwise assert on actual contents\nassert_that(result, equal_to(expected_records), label='contents')","handlingStrategy":"validation","validationCode":"# assert only on pcollections known to have data\ncount = (pcoll | 'count' >> beam.combiners.Count.Globally())\n# or check upstream source/filter logic before asserting non-emptiness","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never assert non-emptiness on a pipeline whose filters may legitimately remove everything","Count elements upstream when debugging empty outputs","Assert exact expected contents rather than just non-emptiness"],"tags":["apache-beam","testing","assertion","empty-pcollection"],"backgroundTag":"empty-result-set","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"}