shikhabhadoria commented on code in PR #41453:
URL: https://github.com/apache/beam/pull/41453#discussion_r4758139997


##########
sdks/python/apache_beam/yaml/yaml_enrichment.py:
##########
@@ -104,5 +125,32 @@ def enrichment_transform(
   if enrichment_handler not in handler_map:
     raise ValueError(f"Unknown enrichment source: {enrichment_handler}")
 
+  if handler_map[enrichment_handler] is None:
+    raise ValueError(
+        f"gcp dependencies not installed. Cannot use {enrichment_handler} "
+        f"handler. Please install using 'pip install apache-beam[gcp]'.")
+
   handler = handler_map[enrichment_handler](**handler_config)
-  return pcoll | Enrichment(source_handler=handler, timeout=timeout)
+  # on_miss/prefix land in a follow-up to #41451. Build kwargs dynamically so
+  # type checkers against current master Enrichment stay clean, and raise if
+  # the YAML asks for those options before that API is available.
+  # error_handling uses Enrichment.with_exception_handling from #41451 via
+  # maybe_with_exception_handling_transform_fn / _PValueWithErrors.
+  enrich_kwargs: dict[str, Any] = {
+      'source_handler': handler,
+      'timeout': timeout,
+  }
+  enrich_params = inspect.signature(Enrichment.__init__).parameters
+  if 'on_miss' in enrich_params:
+    enrich_kwargs['on_miss'] = on_miss
+  elif on_miss not in (None, 'null'):

Review Comment:
   Updated both ValueError messages to remove the internal branch name and 
reference #41356 instead (and added a specific message when the File enrichment 
handler is unavailable).



##########
sdks/python/apache_beam/yaml/yaml_enrichment_test.py:
##########
@@ -15,33 +15,92 @@
 # limitations under the License.
 #
 
+import inspect
 import logging
+import os
+import tempfile
 import unittest
 
 import mock
 
 import apache_beam as beam
 from apache_beam import Row
+from apache_beam.io.requestresponse import UserCodeTimeoutException
 from apache_beam.testing.util import assert_that
 from apache_beam.testing.util import equal_to
+from apache_beam.transforms.enrichment import Enrichment
+from apache_beam.transforms.enrichment import EnrichmentSourceHandler
 from apache_beam.yaml import yaml_provider
+from apache_beam.yaml.yaml_enrichment import FileEnrichmentHandler
 from apache_beam.yaml.yaml_transform import YamlTransform
 
+try:
+  import pyarrow as pa
+  import pyarrow.parquet as pq
+except ImportError:
+  pa = None  # type: ignore[assignment]
+  pq = None  # type: ignore[assignment]
+
 

Review Comment:
   Split the skip guards into `_require_file_handler`, 
`_require_on_miss_and_prefix`, and `_require_exception_handling` (so 
`test_yaml_enrichment_rpc_timeout_routed_to_error_handling` only requires 
`with_exception_handling`), and added mock-based unit tests covering `File` 
handler dispatch, unsupported `on_miss`/`prefix` errors, and full 
`on_miss`/`prefix`/`error_handling` forwarding so all new `yaml_enrichment.py` 
branches execute in CI.



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