apache/beam · error · BeamAssertException
Failed assert: nothing matches the criterion
Error message
Failed assert: nothing matches the criterion
What it means
BeamAssertException raised by a `_not_empty` matcher attached to a filtered pipeline (`_apply_criterion` + `Filter` pipeline in the source) when no element matched the criterion, leaving the filtered output PCollection empty. It signals that the test expected at least one element satisfying the criterion but got none.
Solutions
- Verify the criterion logic — loosen it or fix bugs so at least one element matches.
- Add test input that is guaranteed to satisfy the criterion.
- Print/count elements before the Filter to see whether the input or the predicate is the problem.
Example fix
// before result = input | label >> Map(_apply_criterion) | label + "_filter" >> Filter(lambda e: e is not None) assert_that(result, _not_empty) // after # add an element guaranteed to match criterion_input = input + [element_matching_criterion]
Defensive patterns
Strategy: validation
Validate before calling
# ensure test input contains an element satisfying the criterion assert any(criterion(e) for e in input_elements), 'test input lacks matching element'
Prevention
- Sanity-check criterion functions on test data before pipeline runs
- Include at least one element known to satisfy the criterion in test fixtures
- Count pre-filter elements when tests fail
When it happens
Trigger: Running the criterion-test pipeline (`input | label >> Map(_apply_criterion) | Filter(...)`) with data where the criterion function returns false for every element, so `assert_that(result, _not_empty)` fails.
Common situations: Testing combiners/criteria (e.g. in combiner property tests) with inputs that don't satisfy the predicate; a criterion that is too strict; test fixtures lacking suitable data.
Understand the failure class
Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.
Related errors
- assert_that must be used within a beam.Pipeline context…
- Failed assert: pcol is empty
- passert.Sum( ) = , want
- %s
- The pipeline contains abandoned PAssert(s).
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/bff9a9ae1b2937be.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/python/apache_beam/testing/util.py:444
# similar to assert_that, we choose a label if it already exists.
if label in pipeline.applied_labels:
label_idx = 2
while f"{label}_{label_idx}" in pipeline.applied_labels:
label_idx += 1
label = f"{label}_{label_idx}"
def _apply_criterion(
e=DoFn.ElementParam,
t=DoFn.TimestampParam,
w=DoFn.WindowParam,
p=DoFn.PaneInfoParam):
if criterion(e, t, w, p):
return e, t, w, p
def _not_empty(actual):
actual = list(actual)
if not actual:
raise BeamAssertException('Failed assert: nothing matches the criterion')
result = input | label >> Map(_apply_criterion) | label + "_filter" >> Filter(
lambda e: e is not None)
assert_that(result, _not_empty)
def open_shards(glob_pattern, mode='rt', encoding='utf-8'):
"""Returns a composite file of all shards matching the given glob pattern.
Args:
glob_pattern (str): Pattern used to match files which should be opened.
mode (str): Specify the mode in which the file should be opened. For
available modes, check io.open() documentation.
encoding (str): Name of the encoding used to decode or encode the file.
This should only be used in text mode.
Returns:
A stream with the contents of the opened files.View on GitHub (pinned to 12126d8942)