Skip to content

[Python] Fix FeastFeatureStoreEnrichmentHandler cache key, exception_level handling and temp YAML leak - #41427

Open
ankitdhandharia wants to merge 4 commits into
apache:masterfrom
ankitdhandharia:fix/issue-41347
Open

ankitdhandharia wants to merge 4 commits into
apache:masterfrom
ankitdhandharia:fix/issue-41347

Conversation

@ankitdhandharia

Copy link
Copy Markdown

Fixes #41347

The Feast online feature store enrichment handler had three independent correctness bugs, all in sdks/python/apache_beam/transforms/enrichment_handlers/feast_feature_store.py:

  1. get_cache_key crashed with entity_row_fn. It took the entity-key name returned by entity_row_fn and then re-indexed the input row with it (request._asdict()[entity_id]). When entity_row_fn maps a row column to a differently-named entity key — its whole purpose — that name isn't a column on the row, so caching raised KeyError. It now builds the key from the key/value pairs the function returns (sorted, so compound multi-entity mappings are stable and collision-free), matching how bigtable.py's handler keys off its row-key function.
  2. exception_level was ignored. The constructor stored exception_level but __call__ never consulted it, so missing/None feature values were silently returned. __call__ now warns or raises according to ExceptionLevel (entity-key columns echoed back by Feast are excluded from the "missing" check), following the same pattern as the Bigtable handler.
  3. Downloaded config YAML files leaked. download_fs_yaml_file creates a NamedTemporaryFile(delete=False) but the handler never deleted it. The path is now tracked on the instance and removed in __exit__ and on feature-store construction failure.

Testing

Added focused unit tests in feast_feature_store_test.py that mock out GCS and Feast (CPU-only, no network): a cache-key test with a mapping entity_row_fn and a compound mapping, tests that exception_level=RAISE/WARN fire when feature values are missing (and do not fire when present), and a test that the downloaded YAML is removed on teardown.

Run with apache-beam installed editable (pip install -e .) plus feast, in sdks/python:

Before the fix (the five new regression tests fail for the reasons in the issue — KeyError from get_cache_key, no raise/warn on missing features, and _local_repo_path never recorded/removed):

$ python -m pytest apache_beam/transforms/enrichment_handlers/feast_feature_store_test.py::TestFeastFeatureStoreHandlerUnit -q
5 failed, 1 passed

After the fix:

$ python -m pytest apache_beam/transforms/enrichment_handlers/feast_feature_store_test.py -v -k "mapped_entity_row_fn or features_missing or removes_downloaded or level_raise or level_warn or compound"
5 passed, 5 deselected

$ python -m pytest apache_beam/transforms/enrichment_handlers/feast_feature_store_test.py -q
10 passed

yapf==0.43.0 --diff and pylint (10.00/10) are clean on both changed Python files.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review Summary

This PR fixes three bugs in FeastFeatureStoreEnrichmentHandler: deriving the cache key from the dictionary returned by entity_row_fn rather than re-indexing the input beam.Row, enforcing exception_level (WARN/RAISE) when online feature values are None, and cleaning up the temporary Feast YAML file downloaded during setup. The changes are well-structured and accompanied by focused unit tests.

🔍 General Feedback

  • One minor edge case remains in __enter__: if self.store.get_feature_service(...) raises an exception after FeatureStore is constructed, _remove_local_repo_path() is not called before raising RuntimeError, which would still leak the temporary YAML file.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

@github-actions github-actions Bot added python core size/m M: 50-249 lines changed labels Nov 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @damccorm for label python.
Backup reviewer: claudevdm (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

This pull request likely touches a core component ("core" label). Please review with scrutiny.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

Clean up the downloaded feature store YAML in __enter__ when
get_feature_service raises, not only when FeatureStore construction fails,
and add a regression test.
@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 4.34783% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.00%. Comparing base (37142b3) to head (cd11a08).
⚠️ Report is 18 commits behind head on master.

Files with missing lines Patch % Lines
...nsforms/enrichment_handlers/feast_feature_store.py 4.34% 22 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #41427      +/-   ##
============================================
- Coverage     58.00%   58.00%   -0.01%     
  Complexity     2837     2837              
============================================
  Files          1210     1210              
  Lines        173151   173172      +21     
  Branches       2328     2328              
============================================
+ Hits         100437   100448      +11     
- Misses        70003    70009       +6     
- Partials       2711     2715       +4     
Flag Coverage Δ
python 80.61% <4.34%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@damccorm damccorm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing these! Overall this looks very clean—just a few small comments inline, mainly around marking the new test class with @pytest.mark.uses_feast.

)


class TestFeastFeatureStoreHandlerUnit(unittest.TestCase):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we decorate TestFeastFeatureStoreHandlerUnit with @pytest.mark.uses_feast? Standard precommit suites don't install feast so this file skips there, and the feastIntegrationTest Gradle task (sdks/python/test-suites/direct/common.gradle) collects tests via -m uses_feast.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll need to merge #41595 before this can actually run, but could you also touch https://github.com/damccorm/beam/blob/8dbc89c7ad5819ae51efe4ed978a15c2de74741e/.github/trigger_files/beam_PostCommit_Python.json after that is merged to kick off those tests?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: TestFeastFeatureStoreHandlerUnit now has @pytest.mark.uses_feast (cd11a08), and -m uses_feast picks up all 9 of its tests locally. Once #41595 is merged I'll touch .github/trigger_files/beam_PostCommit_Python.json here to kick off the PostCommit.

- Reset store when the feature service lookup fails in __enter__.
- Build the entity_row_fn cache key from repr(sorted(items)) so values
  such as 1 and '1', or strings containing the separator, cannot collide.
- Mark the unit test class with uses_feast so feastIntegrationTest runs it.
- Add an ExceptionLevel.QUIET test.
@damccorm

Copy link
Copy Markdown
Contributor

Thanks - this LGTM. Lets wait on #41427 (comment) so that we can actually run the tests, and then we can merge here.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: [Python] FeastFeatureStoreEnrichmentHandler crashes get_cache_key with entity_row_fn, ignores exception_level, and leaks temp YAML files

2 participants