jk-shah opened a new issue, #41345:
URL: https://github.com/apache/beam/issues/41345

   ### What happened?
   
   `VertexAIFeatureStoreEnrichmentHandler` 
(`sdks/python/apache_beam/transforms/enrichment_handlers/vertex_ai_feature_store.py`)
 has three related bugs around `NotFound` handling and client initialization:
   
   1. **`UnboundLocalError` when `exception_level=ExceptionLevel.QUIET` (lines 
`164-182`)**:
      When an entity key is not present in Vertex AI Feature Store and 
`fetch_feature_values` raises `google.api_core.exceptions.NotFound`, the 
`except NotFound:` block handles `ExceptionLevel.WARN` (`return request, 
beam.Row()`) and `ExceptionLevel.RAISE`, but has no branch for 
`ExceptionLevel.QUIET`. Execution falls through to line `181` (`response_dict = 
dict(response.proto_struct)`) and crashes with:
      `UnboundLocalError: cannot access local variable 'response' where it is 
not associated with a value`.
   2. **`VertexAIFeatureStoreLegacyEnrichmentHandler` ignores `exception_level` 
on `NotFound` (lines `302-305`)**:
      Unconditionally raises `ValueError` on `NotFound` even when 
`exception_level` is `ExceptionLevel.WARN` (the default) or 
`ExceptionLevel.QUIET`.
   3. **Live network RPCs inside `__init__` (lines `115-125` and `258-268`)**:
      `__init__` instantiates an admin client and calls 
`get_feature_online_store` / `aiplatform.Featurestore(...)` during pipeline 
construction rather than inside `__enter__`, breaking offline pipeline 
validation, CI unit tests without GCP credentials, and template builds.
   
   Minimal reproducer for (1):
   
   ```python
   from unittest import mock
   import apache_beam as beam
   from google.api_core.exceptions import NotFound
   from apache_beam.transforms.enrichment_handlers.utils import ExceptionLevel
   from apache_beam.transforms.enrichment_handlers.vertex_ai_feature_store 
import (
       VertexAIFeatureStoreEnrichmentHandler,
   )
   
   handler = VertexAIFeatureStoreEnrichmentHandler.__new__(
       VertexAIFeatureStoreEnrichmentHandler)
   handler.row_key = 'user_id'
   handler.feature_store_name = 'fs'
   handler.feature_view_name = 'fv'
   handler.feature_view_path = 
'projects/p/locations/us-central1/featureOnlineStores/fs/featureViews/fv'
   handler.exception_level = ExceptionLevel.QUIET
   handler.client = mock.MagicMock()
   handler.client.fetch_feature_values.side_effect = NotFound('missing entity')
   
   handler(beam.Row(user_id='u_missing'))
   # Raises UnboundLocalError: cannot access local variable 'response'
   ```
   
   ### Cause
   
   Missing `return request, beam.Row()` for `ExceptionLevel.QUIET` inside 
`except NotFound:` at lines `171-180`, and eager admin existence checks in 
`__init__` instead of `__enter__`.
   
   ### Issue Priority
   
   Priority: 2 (default / most bugs should be filed as P2)
   
   ### Issue Components
   
   - [x] Component: Python SDK
   - [ ] Component: Java SDK
   - [ ] Component: Go SDK
   - [ ] Component: Typescript SDK
   - [ ] Component: IO connector
   - [ ] Component: Beam YAML
   - [x] Component: Beam ML
   - [ ] Component: Beam examples
   - [ ] Component: Beam playground
   - [ ] Component: Beam katas
   - [ ] Component: Website
   - [ ] Component: Infrastructure
   - [ ] Component: Spark Runner
   - [ ] Component: Flink Runner
   - [ ] Component: Prism Runner
   - [ ] Component: Hazelcast Jet Runner
   - [ ] Component: Google Cloud Dataflow Runner
   


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