{"record":{"id":"b76c4d12a4043a88","repo":"apache/beam","slug":"reference-source-r-and-the-source-r-must-use-the-same-coder","errorCode":null,"errorMessage":"Reference source %r and the source %r must use the same coder. They are using %r and %r respectively instead.","messagePattern":"Reference source %r and the source %r must use the same coder\\. They are using %r and %r respectively instead\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/source_test_utils.py","lineNumber":161,"sourceCode":"    raise ValueError(\n        'reference_source_info must a three-tuple where first'\n        'item of the tuple gives a '\n        'iobase.BoundedSource. Received: %r' % reference_source_info)\n  reference_records = read_from_source(*reference_source_info)\n\n  source_records = []\n  for source_info in sources_info:\n    assert isinstance(source_info, tuple)\n    assert len(source_info) == 3\n    if not (isinstance(source_info, tuple) and len(source_info) == 3 and\n            isinstance(source_info[0], iobase.BoundedSource)):\n      raise ValueError(\n          'source_info must a three tuple where first'\n          'item of the tuple gives a '\n          'iobase.BoundedSource. Received: %r' % source_info)\n    if (type(reference_source_info[0].default_output_coder())\n        != type(source_info[0].default_output_coder())):\n      raise ValueError(\n          'Reference source %r and the source %r must use the same coder. '\n          'They are using %r and %r respectively instead.' % (\n              reference_source_info[0],\n              source_info[0],\n              type(reference_source_info[0].default_output_coder()),\n              type(source_info[0].default_output_coder())))\n    source_records.extend(read_from_source(*source_info))\n\n  if len(reference_records) != len(source_records):\n    raise ValueError(\n        'Reference source must produce the same number of records as the '\n        'list of sources. Number of records were %d and %d instead.' %\n        (len(reference_records), len(source_records)))\n\n  if equal_to(reference_records)(source_records):\n    raise ValueError(\n        'Reference source and provided list of sources must produce the '\n        'same set of records.')","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/source_test_utils.py#L143-L179","documentation":"assert_sources_equal_reference_source compares records read from a reference BoundedSource against those read from candidate sources, which requires identical encoding. Beam raises ValueError when the reference source's default_output_coder type differs from a candidate source's, because byte-level record comparison would be meaningless across coders.","triggerScenarios":"Comparing a source whose default_output_coder() returns, e.g., a ProtoCoder against one returning a FastPrimitivesCoder, or comparing sources of different element types (str vs bytes).","commonSituations":"Testing a new source against a reference implementation written with a different coder, or changing element types in one source but not its test reference.","solutions":["Make the tested source's default_output_coder() return the same coder type as the reference source","Align the element types produced by both sources","Wrap elements in a common coder (e.g. use FastPrimitivesCoder in both) if types differ legitimately","Update the test's reference source after any intentional coder change"],"exampleFix":"// before\nclass MySource(BoundedSource):\n  def default_output_coder(self):\n    return ProtoCoder(MyProto)\n// after\nclass MySource(BoundedSource):\n  def default_output_coder(self):\n    return FastPrimitivesCoder()  # matches reference source","handlingStrategy":"validation","validationCode":"from apache_beam.io import iobase\nassert type(ref[0].default_output_coder()) == type(src[0].default_output_coder())","typeGuard":"def coders_match(ref_source, src):\n    return type(ref_source.default_output_coder()) == type(src.default_output_coder())","tryCatchPattern":"try:\n    source_test_utils.assert_sources_equal_reference_source(ref, sources)\nexcept ValueError as e:\n    logger.error('Coder mismatch between sources: %s', e)","preventionTips":["Keep reference and tested sources producing the same element types","Override default_output_coder consistently across related sources","Re-check coder alignment after changing record schemas in tests"],"tags":["apache-beam","python","testing","coder"],"backgroundTag":"incompatible-source-type","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"}