{"record":{"id":"8e47da2fd04eca2a","repo":"apache/beam","slug":"failed-assert-received-element-is-not-of-type","errorCode":null,"errorMessage":"Failed assert: Received element {} is not of type TestWindowedValue. Did you forget to set reify_windows=True on the assertion?","messagePattern":"Failed assert: Received element (.+?) is not of type TestWindowedValue\\. Did you forget to set reify_windows=True on the assertion\\?","errorType":"exception","errorClass":"BeamAssertException","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/testing/util.py","lineNumber":133,"sourceCode":"        raise BeamAssertException(\n            'Failed assert: window {} not found in any expected ' \\\n            'windows {}'.format(window_key, list(_expected.keys())))\\\n\n      # Remove any matched elements from the window. This is used later on to\n      # assert that all elements in the window were matched with actual\n      # elements.\n      try:\n        _expected[window_key].remove(actual)\n      except ValueError:\n        raise BeamAssertException(\n            'Failed assert: element {} not found in window ' \\\n            '{}:{}'.format(actual, window_key, _expected[window_key]))\\\n\n    # Run the matcher for each window and value pair. Fails if the\n    # windowed_value is not a TestWindowedValue.\n    for windowed_value in value:\n      if not isinstance(windowed_value, TestWindowedValue):\n        raise BeamAssertException(\n            'Failed assert: Received element {} is not of type ' \\\n            'TestWindowedValue. Did you forget to set reify_windows=True ' \\\n            'on the assertion?'.format(windowed_value))\n      match(windowed_value)\n\n    # Finally, some elements may not have been matched. Assert that we removed\n    # all the elements that we received from the expected list. If the list is\n    # non-empty, then there are unmatched elements.\n    for win in _expected:\n      if _expected[win]:\n        raise BeamAssertException(\n            'Failed assert: unmatched elements {} in window {}'.format(\n                _expected[win], win))\n\n\ndef equal_to_per_window(expected_window_to_elements):\n  \"\"\"Matcher used by assert_that to check to assert expected windows.\n","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/testing/util.py#L115-L151","documentation":"equal_to_per_window requires the asserted PCollection to contain TestWindowedValue objects (i.e., windows reified into the elements). Its __call__ type-checks each received item; plain values mean windows were not reified, so per-window matching is impossible, and BeamAssertException is raised with a hint to set reify_windows=True.","triggerScenarios":"Calling assert_that(pcoll, equal_to_per_window({...})) WITHOUT reify_windows=True; the assertion receives plain elements (or non-TestWindowedValue objects) and fails on the first one.","commonSituations":"Copy-pasting an ordinary assert_that/pcol equal_to assertion and swapping in equal_to_per_window without adding the reify_windows flag; using a runner/DoFn that strips window information before the assertion.","solutions":["Pass reify_windows=True to assert_that: assert_that(pcoll, equal_to_per_window(expected), reify_windows=True).","Ensure nothing between the pipeline and the assertion discards windowing information.","If per-window assertions aren't needed, use plain equal_to instead."],"exampleFix":"// before\nassert_that(pcoll, equal_to_per_window({win: ['a']}))\n// after\nassert_that(pcoll, equal_to_per_window({win: ['a']}), reify_windows=True)","handlingStrategy":"type-guard","validationCode":"# ensure the assertion is wired with reified windows\nassert_that(pcoll, equal_to_per_window(expected), reify_windows=True)","typeGuard":"from apache_beam.testing.util import TestWindowedValue\ndef is_test_windowed_value(x) -> bool:\n    return isinstance(x, TestWindowedValue)","tryCatchPattern":"from apache_beam.testing.util import BeamAssertException\ntry:\n    assert_that(pcoll, equal_to_per_window(expected), reify_windows=True)\nexcept BeamAssertException as e:\n    if 'not of type TestWindowedValue' in str(e):\n        logging.error('Add reify_windows=True: %s', e)\n    else:\n        raise","preventionTips":["Always pass reify_windows=True with equal_to_per_window","Never insert a Map that unwraps windowed values before a per-window assertion","Review assertion helpers' signatures for required flags"],"tags":["python","apache-beam","assertion","windowing","test"],"backgroundTag":"type-mismatch","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"}