This is an automated email from the ASF dual-hosted git repository.
tvalentyn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new c90ac7c7a0e [Python] Ignore unknown args with single dash (#25920)
c90ac7c7a0e is described below
commit c90ac7c7a0e8432873c3afe806ae5bb4908f25f4
Author: Ritesh Ghorse <[email protected]>
AuthorDate: Thu Mar 23 13:40:12 2023 -0400
[Python] Ignore unknown args with single dash (#25920)
Co-authored-by: tvalentyn <[email protected]>
---
CHANGES.md | 1 +
sdks/python/apache_beam/options/pipeline_options.py | 12 +++++++++++-
sdks/python/apache_beam/options/pipeline_options_test.py | 4 ++--
3 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index b4a69c62e6f..7fdca4e6914 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -68,6 +68,7 @@
## Breaking Changes
* If a main session fails to load, the pipeline will now fail at worker
startup. ([#25401](https://github.com/apache/beam/issues/25401)).
+* Python pipeline options will now ignore unparsed command line flags prefixed
with a single dash. ([#25943](https://github.com/apache/beam/issues/25943)).
## Deprecations
diff --git a/sdks/python/apache_beam/options/pipeline_options.py
b/sdks/python/apache_beam/options/pipeline_options.py
index 229f04b8a35..be6fe3ebab2 100644
--- a/sdks/python/apache_beam/options/pipeline_options.py
+++ b/sdks/python/apache_beam/options/pipeline_options.py
@@ -347,9 +347,19 @@ class PipelineOptions(HasDisplayData):
else:
parser.add_argument(split[0], type=str)
i += 1
- else:
+ elif unknown_args[i].startswith('--'):
parser.add_argument(unknown_args[i], type=str)
i += 2
+ else:
+ # skip all binary flags used with '-' and not '--'.
+ # ex: using -f instead of --f (or --flexrs_goal) will prevent
+ # argument validation before job submission and can be incorrectly
+ # submitted to job.
+ _LOGGER.warning(
+ "Discarding flag %s, single dash flags are not allowed.",
+ unknown_args[i])
+ i += 2
+ continue
parsed_args, _ = parser.parse_known_args(self._flags)
else:
if unknown_args:
diff --git a/sdks/python/apache_beam/options/pipeline_options_test.py
b/sdks/python/apache_beam/options/pipeline_options_test.py
index 1519da2b3fe..f83f703e33b 100644
--- a/sdks/python/apache_beam/options/pipeline_options_test.py
+++ b/sdks/python/apache_beam/options/pipeline_options_test.py
@@ -355,8 +355,8 @@ class PipelineOptionsTest(unittest.TestCase):
def test_retain_unknown_options_binary_single_dash_store_string(self):
options = PipelineOptions(['-i', 'some_value'])
- result = options.get_all_options(retain_unknown_options=True)
- self.assertEqual(result['i'], 'some_value')
+ with self.assertRaises(KeyError):
+ _ = options.get_all_options(retain_unknown_options=True)['i']
def test_retain_unknown_options_unary_store_true(self):
options = PipelineOptions(['--unknown_option'])