claudevdm commented on code in PR #35904:
URL: https://github.com/apache/beam/pull/35904#discussion_r2421355459


##########
sdks/python/apache_beam/internal/pickler_test.py:
##########
@@ -302,6 +318,18 @@ def test_disable_best_effort_determinism(self):
         dumps(set1, enable_best_effort_determinism=False),
         dumps(set2, enable_best_effort_determinism=False))
 
+  def test_enable_stable_code_identifier_pickling(self):
+    pickler.set_library('cloudpickle')
+    pickled = pickle_depickle(lambda x: x, True)
+    pickled_type = type(pickled)
+    self.assertIsInstance(pickled, pickled_type)

Review Comment:
   I tried
   
   file: module_test.py
   ```
   def mutable_test_function():
       def dynamic_function():
           return "version1"
       return dynamic_function
   ```
   
   file: pickler_test.py
   ```
   def test_stable_identifier_uses_current_code(self):
       """Stable identifiers resolve to current code, frozen bytecode preserves 
original."""
       pickler.set_library('cloudpickle')
       import apache_beam.internal.module_test as module_test
       
       # Get original dynamic function
       func_v1 = module_test.mutable_test_function()
       
       pickled_stable = pickler.dumps(
           func_v1,
           enable_stable_code_identifier_pickling=True)
       
       pickled_frozen = pickler.dumps(
           func_v1,
           enable_stable_code_identifier_pickling=False)
       
       # Save original function for cleanup
       original_function = module_test.mutable_test_function
       
       try:
           # Monkey patch: Replace the entire outer function with v2
           code_v2 = """
   def mutable_test_function():
       def dynamic_function():
           return "version2"
       return dynamic_function
   """
           namespace = {}
           exec(code_v2, namespace)
           module_test.mutable_test_function = 
namespace['mutable_test_function']
           
           # Unpickle both
           func_stable = pickler.loads(pickled_stable)
           func_frozen = pickler.loads(pickled_frozen)
           
           # Stable identifier resolves to NEW code (version2)
           self.assertEqual("version2", func_stable())
           
           # Frozen bytecode uses OLD code (version1)
           self.assertEqual("version1", func_frozen())
           
       finally:
           # Restore original function
           module_test.mutable_test_function = original_function
   ```



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