github-actions[bot] commented on code in PR #40711:
URL: https://github.com/apache/beam/pull/40711#discussion_r4415611848


##########
sdks/python/apache_beam/internal/code_object_pickler.py:
##########
@@ -496,6 +504,17 @@ def _get_arg_count(obj: types.CodeType):
   )
 
 
+def _normalize_const(const):
+  """Normalizes a constant from co_consts for deterministic hashing."""
+  if inspect.iscode(const):
+    return ('__code__', _create_bytecode_hash(const))
+  if isinstance(const, tuple):
+    return tuple(_normalize_const(x) for x in const)
+  if isinstance(const, frozenset):
+    return frozenset(_normalize_const(x) for x in const)

Review Comment:
   **🟡 Medium**: `repr(frozenset(...))` iterates over the `frozenset` in hash 
table order, which depends on `PYTHONHASHSEED` and element insertion/hash 
order, making the resulting `repr` string non-deterministic across different 
Python processes (e.g. between client and worker). Converting normalized 
elements to a sorted tuple (using `repr` as the sort key to handle mixed 
element types) ensures deterministic hashing.
   
   ```suggestion
       return ('__frozenset__', tuple(sorted((_normalize_const(x) for x in 
const), key=repr)))
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to