{"record":{"id":"a224e1f29c8ef297","repo":"apache/beam","slug":"the-key-s-in-gcs-custom-audit-entries-exceeds-the-d-pipeline","errorCode":null,"errorMessage":"The key '%s' in GCS custom audit entries exceeds the %d-character limit.","messagePattern":"The key '(.+?)' in GCS custom audit entries exceeds the (.+?)-character limit\\.","errorType":"validation","errorClass":"argparse.ArgumentError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/options/pipeline_options.py","lineNumber":186,"sourceCode":"  - a maximum of four custom metadata entries are permitted per request.\n  \"\"\"\n  MAX_KEY_LENGTH = 64\n  MAX_VALUE_LENGTH = 1200\n  MAX_ENTRIES = 4\n  GCS_AUDIT_PREFIX = 'x-goog-custom-audit-'\n\n  def _exceed_entry_limit(self):\n    job_audit_entry = _GcsCustomAuditEntriesAction.GCS_AUDIT_PREFIX + 'job'\n    if job_audit_entry in self._custom_audit_entries:\n      return len(\n          self._custom_audit_entries) > _GcsCustomAuditEntriesAction.MAX_ENTRIES\n    else:\n      return len(self._custom_audit_entries) > (\n          _GcsCustomAuditEntriesAction.MAX_ENTRIES - 1)\n\n  def _add_entry(self, key, value):\n    if len(key) > _GcsCustomAuditEntriesAction.MAX_KEY_LENGTH:\n      raise argparse.ArgumentError(\n          None,\n          \"The key '%s' in GCS custom audit entries exceeds the %d-character limit.\"  # pylint: disable=line-too-long\n          % (key, _GcsCustomAuditEntriesAction.MAX_KEY_LENGTH))\n\n    if len(value) > _GcsCustomAuditEntriesAction.MAX_VALUE_LENGTH:\n      raise argparse.ArgumentError(\n          None,\n          \"The value '%s' in GCS custom audit entries exceeds the %d-character limit.\"  # pylint: disable=line-too-long\n          % (value, _GcsCustomAuditEntriesAction.MAX_VALUE_LENGTH))\n\n    if key.startswith(_GcsCustomAuditEntriesAction.GCS_AUDIT_PREFIX):\n      self._custom_audit_entries[key] = value\n    else:\n      self._custom_audit_entries[_GcsCustomAuditEntriesAction.GCS_AUDIT_PREFIX +\n                                 key] = value\n\n  def __call__(self, parser, namespace, values, option_string=None):\n    if not hasattr(namespace, self.dest) or getattr(namespace,","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/options/pipeline_options.py#L168-L204","documentation":"This argparse action validates GCS custom audit entry keys passed via pipeline options. It raises when a key exceeds the maximum allowed key length, since GCS audit metadata has hard character limits enforced upstream.","triggerScenarios":"Calling the GCS custom audit entries option (e.g. --gcs_custom_audit_entries or setting custom audit via PipelineOption) with a key longer than _GcsCustomAuditEntriesAction.MAX_KEY_LENGTH.","commonSituations":"Copy-pasting verbose audit metadata keys from another system; programmatically building audit keys from long identifiers; typo concatenating key=value pairs.","solutions":["Shorten the audit entry key to within MAX_KEY_LENGTH characters","Check the key length before constructing the option and raise a friendlier error or truncate","Use a shorter alias key and keep the long form in the value if the value limit allows"],"exampleFix":"// before\n--gcs_custom_audit_entries=very_long_team_department_cost_center_key=value\n// after\n--gcs_custom_audit_entries=team_key=value","handlingStrategy":"validation","validationCode":"if len(key) > _GcsCustomAuditEntriesAction.MAX_KEY_LENGTH:\n    key = key[:_GcsCustomAuditEntriesAction.MAX_KEY_LENGTH]","typeGuard":"def is_valid_audit_key(key):\n    return isinstance(key, str) and 0 < len(key) <= 80","tryCatchPattern":"try:\n    parse_args(argv)\nexcept argparse.ArgumentError as ex:\n    print(f'audit key too long: {ex}')\n    sys.exit(2)","preventionTips":["Pre-truncate keys before building CLI args","Keep audit keys short and identifier-like","Add length checks in code that generates audit entries"],"tags":["python","argparse","cli","gcs","audit"],"backgroundTag":"value-out-of-range","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"}