Skip to content

[Bug]: [Python] VertexAIFeatureStoreEnrichmentHandler raises UnboundLocalError on NotFound when exception_level=ExceptionLevel.QUIET #41345

Todo

Description

@jk-shah

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

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

  • Component: Python SDK
  • Component: Java SDK
  • Component: Go SDK
  • Component: Typescript SDK
  • Component: IO connector
  • Component: Beam YAML
  • 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

Activity

  1. arijeetmukherjee3108-droid commented on Nov 26, 2026

    @arijeetmukherjee3108-droid
    Contributor

    .take-issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions