kristynsmith commented on code in PR #40711:
URL: https://github.com/apache/beam/pull/40711#discussion_r4470022718


##########
sdks/python/apache_beam/internal/code_object_pickler.py:
##########
@@ -496,6 +504,19 @@ 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 (

Review Comment:
   done



##########
sdks/python/apache_beam/internal/code_object_pickler.py:
##########
@@ -505,4 +526,12 @@ def _create_bytecode_hash(code_object: types.CodeType):
   Returns:
     The hash of the code object.
   """
-  return hashlib.md5(code_object.co_code).hexdigest()
+  hash_input = repr((
+      code_object.co_code,
+      tuple(_normalize_const(c) for c in code_object.co_consts),
+      code_object.co_names,
+      code_object.co_varnames,
+      code_object.co_freevars,
+      code_object.co_cellvars,
+  )).encode('utf-8')

Review Comment:
   done



-- 
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