{"record":{"id":"458eae2cd536a158","repo":"apache/beam","slug":"s-cannot-be-made-deterministic-for-s","errorCode":null,"errorMessage":"%s cannot be made deterministic for '%s'.","messagePattern":"(.+?) cannot be made deterministic for '(.+?)'\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/coders/coders.py","lineNumber":185,"sourceCode":"    deterministic: the ordering of picked entries in maps may vary across\n    executions since there is no defined order, and such a coder is not in\n    general suitable for usage as a key coder in GroupByKey operations, since\n    each instance of the same key may be encoded differently.\n\n    Returns:\n      Whether coder is deterministic.\n    \"\"\"\n    return False\n\n  def as_deterministic_coder(self, step_label, error_message=None):\n    \"\"\"Returns a deterministic version of self, if possible.\n\n    Otherwise raises a value error.\n    \"\"\"\n    if self.is_deterministic():\n      return self\n    else:\n      raise ValueError(\n          error_message or\n          \"%s cannot be made deterministic for '%s'.\" % (self, step_label))\n\n  def estimate_size(self, value):\n    \"\"\"Estimates the encoded size of the given value, in bytes.\n\n    Dataflow estimates the encoded size of a PCollection processed in a pipeline\n    step by using the estimated size of a random sample of elements in that\n    PCollection.\n\n    The default implementation encodes the given value and returns its byte\n    size.  If a coder can provide a fast estimate of the encoded size of a value\n    (e.g., if the encoding has a fixed size), it can provide its estimate here\n    to improve performance.\n\n    Arguments:\n      value: the value whose encoded size is to be estimated.\n","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/coders/coders.py#L167-L203","documentation":"as_deterministic_coder returns the coder unchanged when is_deterministic() is true, otherwise it raises ValueError (with an optional custom message naming the coder and pipeline step) because the operation requires deterministic encoding — e.g. GroupByKey correctness depends on stable serialized bytes.","triggerScenarios":"deterministic_coder(coder, step_label) is called for a step that requires deterministic coders (GroupByKey on non-deterministically-coded keys) and the coder reports is_deterministic() == False and no fallback exists.","commonSituations":"GroupByKey/co-grouping on keys coded with a coder that serializes dicts/objects with unstable ordering (default pickle coder); users coding custom objects as keys without a deterministic coder.","solutions":["Provide a deterministic coder for the key type and register it (coders registry) or wrap via coder.as_deterministic_coder with a real deterministic implementation","Encode keys into deterministic primitives (e.g. sorted JSON bytes, protobuf) before grouping","Pass a custom error_message or a fallback coder where the API allows"],"exampleFix":"// before\npcoll | beam.GroupByKey()  # key coded with default/pickle coder\n// after\npcoll | beam.Map(lambda kv: (json.dumps(kv[0], sort_keys=True).encode(), kv[1])) | beam.GroupByKey()","handlingStrategy":"try-catch","validationCode":"if not coder.is_deterministic():\n    coder = deterministic_alternative(coder)  # e.g. bytes/protobuf key coder","typeGuard":"def key_is_deterministic(coder):\n    return coder.is_deterministic()","tryCatchPattern":"try:\n    coder = coder.as_deterministic_coder(step_label)\nexcept ValueError as e:\n    log.error('need a deterministic coder for %s: %s', step_label, e)\n    coder = fallback_deterministic_coder","preventionTips":["Use deterministic coders for GroupByKey keys (bytes, protobuf, sorted-JSON)","Register deterministic coders for custom types in the coder registry","Test grouping steps with representative keys"],"tags":["python","apache-beam","determinism","serialization"],"backgroundTag":"unsupported-operation","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"}