Repository navigation
[Python] Fix FeastFeatureStoreEnrichmentHandler cache key, exception_level handling and temp YAML leak - #41427
ankitdhandharia wants to merge 4 commits into
Conversation
…level and temp file leak (apache#41347)
There was a problem hiding this comment.
📋 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__: ifself.store.get_feature_service(...)raises an exception afterFeatureStoreis constructed,_remove_local_repo_path()is not called before raisingRuntimeError, which would still leak the temporary YAML file.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @damccorm for label python. 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 Available commands:
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 Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…e-41347 # Conflicts: # CHANGES.md
damccorm
left a comment
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
- 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.
|
Thanks - this LGTM. Lets wait on #41427 (comment) so that we can actually run the tests, and then we can merge here. |
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:get_cache_keycrashed withentity_row_fn. It took the entity-key name returned byentity_row_fnand then re-indexed the input row with it (request._asdict()[entity_id]). Whenentity_row_fnmaps a row column to a differently-named entity key — its whole purpose — that name isn't a column on the row, so caching raisedKeyError. 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 howbigtable.py's handler keys off its row-key function.exception_levelwas ignored. The constructor storedexception_levelbut__call__never consulted it, so missing/Nonefeature values were silently returned.__call__now warns or raises according toExceptionLevel(entity-key columns echoed back by Feast are excluded from the "missing" check), following the same pattern as the Bigtable handler.download_fs_yaml_filecreates aNamedTemporaryFile(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.pythat mock out GCS and Feast (CPU-only, no network): a cache-key test with a mappingentity_row_fnand a compound mapping, tests thatexception_level=RAISE/WARNfire 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-beaminstalled editable (pip install -e .) plusfeast, insdks/python:Before the fix (the five new regression tests fail for the reasons in the issue —
KeyErrorfromget_cache_key, no raise/warn on missing features, and_local_repo_pathnever recorded/removed):After the fix:
yapf==0.43.0 --diffandpylint(10.00/10) are clean on both changed Python files.