{"record":{"id":"f3eb85145154c276","repo":"apache/beam","slug":"value-length-allowed-length","errorCode":null,"errorMessage":"value length {} > allowed length {}","messagePattern":"value length (.+?) > allowed length (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/typehints/schemas.py","lineNumber":1317,"sourceCode":"\n@LogicalType._register_internal\nclass FixedBytes(PassThroughLogicalType[bytes, np.int32]):\n  \"\"\"A logical type for fixed-length bytes.\"\"\"\n  @classmethod\n  def urn(cls):\n    return common_urns.fixed_bytes.urn\n\n  def __init__(self, length: np.int32):\n    self.length = length\n\n  @classmethod\n  def language_type(cls) -> type:\n    return bytes\n\n  def to_language_type(self, value: bytes):\n    length = len(value)\n    if length > self.length:\n      raise ValueError(\n          \"value length {} > allowed length {}\".format(length, self.length))\n    elif length < self.length:\n      # padding at the end\n      value = value + b'\\0' * (self.length - length)\n\n    return value\n\n  @classmethod\n  def argument_type(cls):\n    return np.int32\n\n  def argument(self):\n    return self.length\n\n\n@LogicalType._register_internal\nclass VariableBytes(PassThroughLogicalType[bytes, np.int32]):\n  \"\"\"A logical type for variable-length bytes with specified maximum length.\"\"\"","sourceCodeStart":1299,"sourceCodeEnd":1335,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/typehints/schemas.py#L1299-L1335","documentation":"The fixed-bytes logical type (FixedBytes, from a length argument) rejects values longer than the declared length in to_language_type(). Shorter values are zero-padded to the fixed length; longer values raise ValueError because fixed-width bytes cannot hold them.","triggerScenarios":"Converting a bytes value whose len(value) exceeds the FixedBytes logical type's length, e.g. FixedBytes(length=4).to_language_type(b'toolong'); decoding schema data whose underlying bytes grew beyond the declared fixed width.","commonSituations":"Declaring a fixed byte width smaller than actual payload (e.g. hashing with SHA-256 but declaring length=16); schema evolved to wider values after the fixed length was fixed at write time; miscounting expected field width.","solutions":["Increase the FixedBytes length argument to at least the maximum value size.","Truncate or hash values to fit the declared length before conversion.","Switch to a variable-length Bytes logical type (or plain bytes) if sizes are not truly fixed."],"exampleFix":"// before\nFixedBytes(length=4).to_language_type(b'hello')  # ValueError\n\n// after\nFixedBytes(length=8).to_language_type(b'hello')  # b'hello\\x00\\x00\\x00'","handlingStrategy":"validation","validationCode":"def fits_fixed_bytes(value: bytes, length: int) -> bool:\n    return len(value) <= length","typeGuard":null,"tryCatchPattern":"try:\n    out = fixed_bytes_lt.to_language_type(value)\nexcept ValueError:\n    out = fixed_bytes_lt.to_language_type(value[:fixed_bytes_lt.length])  # truncate","preventionTips":["Set FixedBytes length to the exact known payload size (e.g. digest size of your hash).","Assert value lengths at data-production time, before schema conversion.","Prefer variable-length bytes when sizes can vary."],"tags":["python","apache-beam","bytes","length-limit","logical-type"],"backgroundTag":"payload-too-large","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"}