You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by xq...@apache.org on 2025/04/29 17:46:12 UTC

(beam) branch master updated: Improve validation error message for chain transform (#34708)

This is an automated email from the ASF dual-hosted git repository.

xqhu 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 49a46c9c571 Improve validation error message for chain transform (#34708)
49a46c9c571 is described below

commit 49a46c9c57183b2cb46356d811739a483dfd707f
Author: Shubham Jaiswal <70...@users.noreply.github.com>
AuthorDate: Tue Apr 29 23:16:07 2025 +0530

    Improve validation error message for chain transform (#34708)
    
    * error message for chain transform
    
    * adding unit test
    
    * fix lint
---
 sdks/python/apache_beam/yaml/yaml_transform.py     |  6 ++++++
 .../apache_beam/yaml/yaml_transform_unit_test.py   | 23 ++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/sdks/python/apache_beam/yaml/yaml_transform.py b/sdks/python/apache_beam/yaml/yaml_transform.py
index 45663c4cd7e..2c6734dbf29 100644
--- a/sdks/python/apache_beam/yaml/yaml_transform.py
+++ b/sdks/python/apache_beam/yaml/yaml_transform.py
@@ -85,6 +85,12 @@ def validate_against_schema(pipeline, strictness):
     jsonschema.validate(pipeline, pipeline_schema(strictness))
   except jsonschema.ValidationError as exn:
     exn.message += f" around line {_closest_line(pipeline, exn.path)}"
+    # validation message for chain-type transform
+    if (exn.schema_path[-1] == 'not' and
+        exn.schema_path[-2] in ['input', 'output']):
+      exn.message = (
+          f"'{exn.schema_path[-2]}' should not be used "
+          "along with 'chain' type transforms. " + exn.message)
     raise exn
 
 
diff --git a/sdks/python/apache_beam/yaml/yaml_transform_unit_test.py b/sdks/python/apache_beam/yaml/yaml_transform_unit_test.py
index 11ef2c5e22a..0ea95228aee 100644
--- a/sdks/python/apache_beam/yaml/yaml_transform_unit_test.py
+++ b/sdks/python/apache_beam/yaml/yaml_transform_unit_test.py
@@ -38,8 +38,14 @@ from apache_beam.yaml.yaml_transform import preprocess
 from apache_beam.yaml.yaml_transform import preprocess_flattened_inputs
 from apache_beam.yaml.yaml_transform import preprocess_windowing
 from apache_beam.yaml.yaml_transform import push_windowing_to_roots
+from apache_beam.yaml.yaml_transform import validate_against_schema
 from apache_beam.yaml.yaml_utils import SafeLineLoader
 
+try:
+  import jsonschema
+except ImportError:
+  jsonschema = None
+
 
 def new_pipeline():
   return beam.Pipeline(
@@ -291,6 +297,23 @@ class MainTest(unittest.TestCase):
         r"Cannot define explicit inputs on chain pipeline"):
       chain_as_composite(spec)
 
+  def test_validate_against_schema_with_transform_input(self):
+    spec = '''
+        pipeline:
+          type: chain
+          transforms:
+            - type: Create
+              config:
+                elements: [1, 2, 3]
+            - type: LogForTesting
+              input: Create
+      '''
+    spec = yaml.load(spec, Loader=SafeLineLoader)
+    with self.assertRaisesRegex(jsonschema.ValidationError,
+                                r"'input' should not be used "
+                                r"along with 'chain' type transforms.*"):
+      validate_against_schema(spec, 'generic')
+
   def test_normalize_source_sink(self):
     spec = '''
         source: