{"record":{"id":"cfad311e97d67f8f","repo":"apache/beam","slug":"no-fallback","errorCode":null,"errorMessage":"No fallback.","messagePattern":"No fallback\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/coders/coder_impl.py","lineNumber":1578,"sourceCode":"\n\nclass _OrderedUnionCoderImpl(StreamCoderImpl):\n  def __init__(self, coder_impl_types, fallback_coder_impl):\n    assert len(coder_impl_types) < 128\n    self._types, self._coder_impls = zip(*coder_impl_types)\n    self._fallback_coder_impl = fallback_coder_impl\n\n  def encode_to_stream(self, value, out, nested):\n    value_t = type(value)\n    for (ix, t) in enumerate(self._types):\n      if value_t is t:\n        out.write_byte(ix)\n        c = self._coder_impls[ix]  # for typing\n        c.encode_to_stream(value, out, nested)\n        break\n    else:\n      if self._fallback_coder_impl is None:\n        raise ValueError(\"No fallback.\")\n      out.write_byte(0xFF)\n      self._fallback_coder_impl.encode_to_stream(value, out, nested)\n\n  def decode_from_stream(self, in_stream, nested):\n    ix = in_stream.read_byte()\n    if ix == 0xFF:\n      if self._fallback_coder_impl is None:\n        raise ValueError(\"No fallback.\")\n      return self._fallback_coder_impl.decode_from_stream(in_stream, nested)\n    else:\n      c = self._coder_impls[ix]  # for typing\n      return c.decode_from_stream(in_stream, nested)\n\n\nclass WindowedValueCoderImpl(StreamCoderImpl):\n  \"\"\"For internal use only; no backwards-compatibility guarantees.\n\n  A coder for windowed values.\"\"\"","sourceCodeStart":1560,"sourceCodeEnd":1596,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/coders/coder_impl.py#L1560-L1596","documentation":"FastPrimitivesCoderImpl tries each of its specialized coder impls; when none can encode the value it falls back to writing byte 0xFF and delegating to _fallback_coder_impl. If no fallback coder was configured, Beam raises ValueError('No fallback.') because the value cannot be encoded by any available coder.","triggerScenarios":"Encoding a value that none of the fast primitive coder impls accept (not a supported primitive/bytes etc.) with a FastPrimitivesCoderImpl constructed without a fallback coder impl (fallback is None).","commonSituations":"Directly constructing the fast-primitives coder without a fallback and then sending non-primitive objects (custom classes, complex types); internal pipelines assuming primitives only but a transform emits a richer type.","solutions":["Provide a fallback coder impl (e.g., a pickling or ProtoCoder-based impl) when constructing the fast-primitives coder","Ensure the values being encoded are the primitives the fast coder supports (bytes, str, int, float, bool, etc.)","Use a regular coder (e.g., PickleCoder) for non-primitive values instead of the fast-primitives coder","Locate the transform emitting non-primitive elements and coerce its output to supported primitives"],"exampleFix":"// before\nimpl = FastPrimitivesCoderImpl(fallback_coder_impl=None)\nimpl.encode_to_stream(MyCustomClass(), out, False)  # ValueError: No fallback.\n// after\nimpl = FastPrimitivesCoderImpl(\n    fallback_coder_impl=PickleCoder().get_impl())\nimpl.encode_to_stream(MyCustomClass(), out, False)  # encoded via fallback","handlingStrategy":"validation","validationCode":"PRIMITIVES = (bytes, str, int, float, bool, type(None))\nassert isinstance(value, PRIMITIVES) or fallback_coder_impl is not None, \\\n    f'non-primitive {type(value)} requires a fallback coder'","typeGuard":"def encodable_without_fallback(v: object) -> bool:\n    return isinstance(v, (bytes, str, int, float, bool, type(None)))","tryCatchPattern":"try:\n    impl.encode_to_stream(value, out, nested)\nexcept ValueError as e:\n    if str(e) == 'No fallback.':\n        PickleCoder().get_impl().encode_to_stream(value, out, nested)\n    else:\n        raise","preventionTips":["Always configure a fallback coder impl when building FastPrimitivesCoderImpl","Keep transform outputs restricted to primitive types when using the fast coder","Use a general coder (PickleCoder/ProtoCoder) for custom classes"],"tags":["python","apache-beam","coding","fallback","serialization"],"backgroundTag":"missing-dependency","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"}