Skip to content

Deep copy PipelineOptions and keep the input intact. #34723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion sdks/python/apache_beam/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

import abc
import contextlib
import copy
import logging
import os
import re
Expand Down Expand Up @@ -171,7 +172,9 @@ def __init__(

if options is not None:
if isinstance(options, PipelineOptions):
self._options = options
# Make a deep copy of options since they could be overwritten in later
# steps.
self._options = copy.deepcopy(options)
else:
raise ValueError(
'Parameter options, if specified, must be of type PipelineOptions. '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,12 @@ def test_cleanup_by_a_pipeline(self):
# Pipeline association is cleaned up.
self.assertNotIn(p, self.clusters.pipelines)
self.assertNotIn(p, dcm.pipelines)
self.assertEqual(options.view_as(FlinkRunnerOptions).flink_master, '[auto]')
# The internal option in the pipeline is overwritten.
self.assertEqual(
p.options.view_as(FlinkRunnerOptions).flink_master, '[auto]')
# The original option is unchanged.
self.assertEqual(
options.view_as(FlinkRunnerOptions).flink_master, meta.master_url)
# The cluster is unknown now.
self.assertNotIn(meta, self.clusters.dataproc_cluster_managers)
self.assertNotIn(meta.master_url, self.clusters.master_urls)
Expand Down Expand Up @@ -423,10 +428,17 @@ def test_not_cleanup_if_multiple_pipelines_share_a_manager(self):
# Pipeline association of p is cleaned up.
self.assertNotIn(p, self.clusters.pipelines)
self.assertNotIn(p, dcm.pipelines)
self.assertEqual(options.view_as(FlinkRunnerOptions).flink_master, '[auto]')
# The internal option in the pipeline is overwritten.
self.assertEqual(
p.options.view_as(FlinkRunnerOptions).flink_master, '[auto]')
# The original option is unchanged.
self.assertEqual(
options.view_as(FlinkRunnerOptions).flink_master, meta.master_url)
# Pipeline association of p2 still presents.
self.assertIn(p2, self.clusters.pipelines)
self.assertIn(p2, dcm.pipelines)
self.assertEqual(
p2.options.view_as(FlinkRunnerOptions).flink_master, meta.master_url)
self.assertEqual(
options2.view_as(FlinkRunnerOptions).flink_master, meta.master_url)
# The cluster is still known.
Expand Down
Loading