praneetnadella commented on code in PR #36738:
URL: https://github.com/apache/beam/pull/36738#discussion_r2501088115
##########
sdks/python/apache_beam/internal/cloudpickle_pickler.py:
##########
@@ -37,13 +37,14 @@
from apache_beam.internal import code_object_pickler
from apache_beam.internal.cloudpickle import cloudpickle
+from apache_beam.internal.code_object_pickler import get_normalized_path
DEFAULT_CONFIG = cloudpickle.CloudPickleConfig(
- skip_reset_dynamic_type_state=True)
+ skip_reset_dynamic_type_state=True,
filepath_interceptor=get_normalized_path)
NO_DYNAMIC_CLASS_TRACKING_CONFIG = cloudpickle.CloudPickleConfig(
Review Comment:
Done.
##########
sdks/python/apache_beam/internal/cloudpickle_pickler_test.py:
##########
@@ -220,6 +224,37 @@ def test_best_effort_determinism_not_implemented(self):
'Ignoring unsupported option: enable_best_effort_determinism',
'\n'.join(l.output))
+ @mock.patch.object(
+ beam_cloudpickle.DEFAULT_CONFIG, 'filepath_interceptor', autospec=True)
+ def test_default_config_interceptor(self, mock_filepath_interceptor):
+ """Tests config.filepath_interceptor is called for CodeType pickling."""
+ mock_filepath_interceptor.side_effect = (
+ code_object_pickler.get_normalized_path)
+
+ def sample_func():
+ return "Beam"
+
+ code_obj = sample_func.__code__
+ original_filename = os.path.abspath(code_obj.co_filename)
+
+ try:
+ pickled_code = beam_cloudpickle.dumps(code_obj)
+ unpickled_code = beam_cloudpickle.loads(pickled_code)
+
+ mock_filepath_interceptor.assert_called()
+
+ unpickled_filename = os.path.abspath(unpickled_code.co_filename)
+ self.assertEqual(unpickled_filename, original_filename)
+
+ except AttributeError as e:
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]