Skip to content

fix: Compare the transformation in BatchFeatureView equality - #7240

Open
mmporong wants to merge 2 commits into
feast-dev:masterfrom
mmporong:fix-bfv-eq-transformation
Open

mmporong wants to merge 2 commits into
feast-dev:masterfrom
mmporong:fix-bfv-eq-transformation

Conversation

@mmporong

@mmporong mmporong commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

BatchFeatureView has no __eq__ of its own, so it inherits FeatureView.__eq__, which does not look at the UDF, udf_string or mode. Two batch feature views that differ only in their transformation compare equal.

Both registries use this equality when a view is applied with an explicit version that already exists: they compare the user's view against the active one (user_fv_copy != active_fv in infra/registry/registry.py and infra/registry/sql.py) and raise FeatureViewPinConflict if the definition was also changed. For a BatchFeatureView, pinning version="v0" together with a new UDF passes that check, restores the v0 snapshot and drops the new UDF without an error. The same pin with a changed schema raises FeatureViewPinConflict on both registries.

registry.apply_feature_view(make_view(udf_a, "udf_a source"), project)  # v0
registry.apply_feature_view(make_view(udf_b, "udf_b source"), project)  # v1
registry.apply_feature_view(make_view(udf_c, "udf_c source", version="v0"), project)
# master: no error, v0 is restored and udf_c is dropped
# this PR: FeatureViewPinConflict

This PR adds BatchFeatureView.__eq__. It calls FeatureView.__eq__ and then compares the transformation with _transformation_changed, the helper that _schema_or_udf_changed uses since #7191 (the UDF source text when both views have it, otherwise the code object, defaults and closure). The transformation class follows the mode, so a mode change with the same UDF is also caught. Views loaded with skip_udf=True only hold the transformation proto, so for those the raw protos are compared. __hash__ is kept, since defining __eq__ alone would make the class unhashable. This is the same kind of fix as #7034 for StreamFeatureView.

The second commit makes that helper ignore what is not part of the UDF. For a UDF without udf_string that dill stores by value (closures, lambdas, functions defined in __main__), _udf_changed compared whole code objects and captured values, so a function that only moved within its file counted as changed (the code object holds the first line number and line table), and so did a UDF that captures a NumPy array (the copy loaded from the registry holds its own array, and == on two arrays has no single truth value). Through the new __eq__ such a pin raised FeatureViewPinConflict for an unchanged UDF, and on master the same comparison already made a plain re-apply store a new version. _udf_changed now clears source positions (nested code included) before comparing code objects and compares arrays by shape, dtype and contents. A changed constant, default, closure value or array is still a change.

batch_engine and aggregations are not compared, because to_proto() does not store them and a view would no longer equal its own from_proto(to_proto()) round trip.

The SQL registry's unchanged-write check in _apply_object is not reached for a BatchFeatureView (deserialize_registry_values only matches the exact FeatureView type), so SQL registry writes behave as before.

Not changed: after a pin restores a snapshot that differs from the declaration, applying the same declaration again raises FeatureViewPinConflict, because the pin check compares the declaration with the active definition and does not keep the declaration it accepted. Master already does this for a schema rollback on both registries; with the UDF now compared, a UDF-only rollback behaves the same way.

Which issue(s) this PR fixes:

No linked issue. This was found by reading the registry pin check after #7034 and #7191.

Checks

  • I've made sure the tests are passing.
  • My commits are signed off (git commit -s)
  • My PR title follows conventional commits format

Testing Strategy

  • Unit tests
  • Integration tests
  • Manual tests
  • Testing is not required for this change

Python 3.12, offline container with the pinned py3.12-requirements.txt plus the test, gRPC, BigQuery and AWS extras. pyspark was not installed.

  • Added test_batch_feature_view_eq_compares_transformation in tests/unit/test_feature_views.py (different UDFs, from_proto(to_proto()) round trip, skip_udf=True views, hashing) and test_pin_batch_feature_view_rejects_changed_udf in tests/unit/infra/registry/test_file_registry.py (pin plus a new UDF raises; pin with the active definition still restores v0). With batch_feature_view.py restored to master, both fail (views with different UDFs compare equal; DID NOT RAISE FeatureViewPinConflict). With this PR they pass.
  • Added test_pin_batch_feature_view_compares_udf_without_source in tests/unit/infra/registry/test_file_registry.py for UDFs without udf_string: moved, reformatted (blank line in the body) and same_array must pin without a conflict and be seen as unchanged by _schema_or_udf_changed; moved_and_edited and edited_array must still raise. With the first commit only, moved, reformatted and same_array fail; with the second commit all 5 pass.
  • Script against the file registry and a SQLite SqlRegistry: pin plus a new UDF gives no error on master and FeatureViewPinConflict with this PR on both. For UDFs without udf_string, a moved factory UDF and one capturing np.array([1, 2]) pin without a conflict and do not create a new version on re-apply; np.array([1, 3]) and a changed constant still raise on the pin. A module-level function in an importable module (pickled by reference) behaves the same on master and with this PR. from_proto(to_proto(v)) == v still holds for pandas and python views and for sql views with and without udf_string. disable_feature_view-style re-apply and a state change on a BatchFeatureView are stored on both registries, as on master.
  • Python 3.11.18 and 3.12.16: the normalized code comparison ignores a moved, re-indented or reformatted function and still separates a changed constant, a changed nested generator expression, 1 from 1.0 and 0.0 from -0.0.
  • tests/unit/test_feature_views.py, tests/unit/infra/registry/, test_stream_feature_view.py, test_eq_cross_type.py, test_feature_view_versioning.py, test_online_config_apply.py, test_label_view.py, test_materialize_version_forwarding.py, test_feature_view_state.py, test_unit_feature_store.py, local_feast_tests/, diff/ and transformation/: 352 passed, 5 failed with this PR; 345 passed, 5 failed on master. The difference is the 7 tests this PR adds. The 5 failures on both are StreamFeatureView tests that need SparkTransformation (pyspark), and 2 modules (test_infra_diff.py, test_snowflake_registry.py) are not collected on both because of extras I did not install.
  • tests/integration/registration/test_versioning.py: 43 passed on master and with this PR.
  • ruff check and ruff format --check (0.17.6) on the 3 changed files, and mypy (1.11.2) on feast/batch_feature_view.py: no issues.

Misc

The first checkbox is left open: the full test suite was not run (see the failures above, which also happen on master).


Devin Review

BatchFeatureView inherited FeatureView.__eq__, which does not look at the
UDF or mode, so two views that differ only in their transformation
compared equal. The registries use this equality to reject a version pin
that also changes the definition, so pinning a BatchFeatureView to an
earlier version together with a new UDF restored the old version and
dropped the new UDF without raising FeatureViewPinConflict.

Compare the transformation the way _schema_or_udf_changed does, compare
the raw protos for views loaded with skip_udf=True, and keep the class
hashable.

Signed-off-by: Lim-jooyoung <mmporong@gmail.com>
@mmporong
mmporong requested a review from a team as a code owner November 25, 2026 23:15

@devin-ai-integration devin-ai-integration 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.

Devin Review found 2 potential issues.

6 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment on lines +215 to +218
return not _transformation_changed(
self.feature_transformation,
getattr(other, "feature_transformation", None),
)

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.

🔴 Repeat apply fails after rollback

After a successful rollback to a different UDF, BatchFeatureView.__eq__ rejects the same pin declaration on the next apply. The pin check compares the declaration with the restored snapshot, not the definition it accepted before the rollback.

Learn more

To roll back a feature view, an operator changes only its version in the repository. The file registry and SQL registry validate that declaration against the active version, then replace the active definition with the older snapshot. They do not retain the declaration they accepted. On the next apply, the declaration is unchanged but the comparison target is now the older snapshot. Before this change, a UDF-only difference did not reject the repeat apply.

Example: Register v0 with UDF A, then v1 with UDF B. Set version="v0" without changing UDF B. The first apply activates A; the second apply of the same repository raises FeatureViewPinConflict.

Recommended fix: Make an exact repeat of an accepted pin a no-op in both registries. Retain the validated pin declaration or its stable fingerprint so the check can distinguish a repeat from a newly edited declaration. Do not bypass the guard solely because the requested version is already active, since that would silently discard new edits. Add a regression that repeats the successful pin and then attempts the same pin with a third UDF.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reproduced on the file registry and a SQLite SqlRegistry. For a UDF-only rollback this is right: after version="v0" restores v0, applying the same declaration again raises FeatureViewPinConflict, where master accepted it.

The pin check already behaves this way on master for every field it compares. With v0 and v1 differing only in schema (plain FeatureView or BatchFeatureView), the first pin restores v0 and the identical second apply raises FeatureViewPinConflict on both registries:

v0 -> v1 change 2nd identical pin, master 2nd identical pin, this PR pin with a new edit, master pin with a new edit, this PR
schema FeatureViewPinConflict FeatureViewPinConflict FeatureViewPinConflict FeatureViewPinConflict
UDF only ok FeatureViewPinConflict ok, new UDF dropped FeatureViewPinConflict

The check compares the declaration with the active definition and does not keep the declaration it accepted, so it cannot tell a repeat from a new edit. Now that the UDF is compared, a UDF-only rollback behaves like a schema rollback. Keeping the accepted pin (or a fingerprint of it) would change the pin flow for all feature view types in both registries, so I left it out of this PR. I can open a follow-up for that if you want it.

Comment on lines +215 to +218
return not _transformation_changed(
self.feature_transformation,
getattr(other, "feature_transformation", None),
)

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.

🟡 False pin conflicts for unchanged UDFs

When a UDF has no source text, BatchFeatureView.__eq__ rejects valid pins after the function moves to another line. _udf_changed also treats identical NumPy arrays captured by separately loaded UDFs as a change.

Learn more

The constructor accepts a callable with no source string. Feast serializes that callable and restores it when loading the active view. The new equality check sends these functions through _udf_changed, which compares whole code objects and captured values. Code-object equality includes the first line number. Tuple equality also needs a single truth value for each capture, which a multi-element NumPy array comparison cannot supply. The helper reports a change in either case, so the pin guard rejects the rollback even though its transformation did not change.

Example: Declare a SQL UDF in a factory without udf_string and publish v0 and v1. Add a blank line before the factory while preparing a rollback to v0. The v1 callable and stored callable return the same query, but the shifted first line triggers FeatureViewPinConflict. A Pandas UDF capturing np.array([1, 2]) can hit the same conflict without moving any code, because the stored callable has its own copy of the array.

Recommended fix: Compare executable code and constants without source positions, including for nested code objects. Compare supported array captures and defaults explicitly by shape, dtype, and contents. Keep regression tests for changed constants, defaults, and closures so the pin guard still rejects real edits.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed and fixed in 565de02.

For a UDF without udf_string that dill stores by value (closures, lambdas, functions defined in __main__), the pin raised FeatureViewPinConflict when the factory only moved down one line, and when the UDF captured np.array([1, 2]). On master the same comparison already made a plain re-apply store a new version for these UDFs.

_udf_changed now clears the source positions (first line number and line table, nested code included) before comparing code objects, and compares arrays by shape, dtype and contents. A moved, reformatted or array-capturing UDF no longer raises on a pin or stores a new version on re-apply. A changed constant, default, closure value or array still does. A module-level function in an importable module is pickled by reference and was not affected before or after.

Added test_pin_batch_feature_view_compares_udf_without_source (moved, reformatted, moved_and_edited, same_array, edited_array). moved, reformatted and same_array fail without the fix.

@codecov-commenter

codecov-commenter commented Nov 25, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 92.30769% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.18%. Comparing base (a291a0f) to head (565de02).

Files with missing lines Patch % Lines
sdk/python/feast/batch_feature_view.py 92.30% 1 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7240      +/-   ##
==========================================
+ Coverage   54.10%   54.18%   +0.07%     
==========================================
  Files         467      467              
  Lines       58940    58965      +25     
  Branches     8688     8694       +6     
==========================================
+ Hits        31890    31949      +59     
+ Misses      24892    24855      -37     
- Partials     2158     2161       +3     
Flag Coverage Δ
go-feature-server 30.96% <ø> (ø)
python-unit 55.78% <92.30%> (+0.08%) ⬆️
Files with missing lines Coverage Δ
sdk/python/feast/batch_feature_view.py 85.60% <92.30%> (+1.49%) ⬆️

... and 4 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a291a0f...565de02. Read the comment docs.

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

…atureView UDFs

BatchFeatureView.__eq__ sends the version pin check through
_udf_changed, which compared whole code objects and captured values.
For a UDF without udf_string, a function that only moved within its
file counted as changed, because the code object holds the first line
number and the line table. A UDF that captures a NumPy array counted as
changed too: the copy loaded from the registry holds its own array, and
== on two arrays has no single truth value. Pinning such a view raised
FeatureViewPinConflict although the UDF was unchanged, and a plain
re-apply stored a new version.

Clear the source positions of the code object and of the code nested in
it before comparing, and compare arrays by shape, dtype and contents.

Signed-off-by: Lim-jooyoung <mmporong@gmail.com>

@franciscojavierarceo franciscojavierarceo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the repeated pin finding still blocks this change. the existing schema limitation does not make it safe to introduce the same failure for UDF-only rollbacks: after the first apply restores v0, an identical second apply now raises FeatureViewPinConflict in both registries. we need to preserve an accepted pin declaration so its exact repeat succeeds while a newly edited UDF is rejected, with regressions for both file and SQL registries.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants