Visitar URL original
fix: UDF/ODFV source rehydrate (+ Postgres / online cache) by aniketpalu · Pull Request #6655 · feast-dev/feast · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: compare UDF transformations by udf_string when present
Source-first from_proto rebuilds callables whose bytecode differs from
the live repo function; requiring co_code equality made no-op feast apply
rewrite ODFVs and broke universal CLI integration tests.

Signed-off-by: Aniket Paluskar <apaluska@redhat.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
  • Loading branch information
aniketpalu and cursoragent committed Aug 11, 2026
commit 8485ae7a9d9a1bc238e267ee9bf6d9ffbafbaf85
17 changes: 10 additions & 7 deletions sdk/python/feast/transformation/pandas_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,16 @@ def __eq__(self, other):
if not isinstance(other, PandasTransformation):
return False

if (
self.udf_string != other.udf_string
or self.udf.__code__.co_code != other.udf.__code__.co_code
):
return False

return True
# udf_string is the canonical diff identity. Source-first from_proto
# rebuilds a new callable (strip+exec) whose bytecode differs from the
# live repo function even when the source is unchanged — do not require
# co_code equality when both sides have source text.
left = self.udf_string or ""
right = other.udf_string or ""
if left and right:
return left == right

return self.udf.__code__.co_code == other.udf.__code__.co_code

@classmethod
def from_proto(cls, user_defined_function_proto: UserDefinedFunctionProto):
Expand Down
17 changes: 10 additions & 7 deletions sdk/python/feast/transformation/python_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,16 @@ def __eq__(self, other):
if not isinstance(other, PythonTransformation):
return False

if (
self.udf_string != other.udf_string
or self.udf.__code__.co_code != other.udf.__code__.co_code
):
return False

return True
# udf_string is the canonical diff identity. Source-first from_proto
# rebuilds a new callable (strip+exec) whose bytecode differs from the
# live repo function even when the source is unchanged — do not require
# co_code equality when both sides have source text.
left = self.udf_string or ""
right = other.udf_string or ""
if left and right:
return left == right

return self.udf.__code__.co_code == other.udf.__code__.co_code

def __reduce__(self):
"""Support for pickle/dill serialization."""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pandas as pd

from feast.transformation.pandas_transformation import PandasTransformation
from feast.transformation.python_transformation import PythonTransformation
from feast.transformation.udf_rehydrate import resolve_udf


def pandas_udf(features_df: pd.DataFrame) -> pd.DataFrame:
Expand All @@ -16,3 +18,32 @@ def test_init_pandas_transformation():
transformed_df = transformation.transform(features_df)
assert transformed_df["output1"].values[0] == 1
assert transformed_df["output2"].values[1] == 3


_UDF_SOURCE = '''def pandas_udf(features_df):
df = __import__("pandas").DataFrame()
df["output1"] = features_df["feature1"]
df["output2"] = features_df["feature2"]
return df
'''


def test_pandas_transformation_eq_uses_udf_string_not_bytecode():
"""Repo vs source-rehydrated callables must compare equal when source matches."""
rehydrated = resolve_udf(udf_string=_UDF_SOURCE, preferred_name="pandas_udf")
assert pandas_udf.__code__.co_code != rehydrated.__code__.co_code

left = PandasTransformation(udf=pandas_udf, udf_string=_UDF_SOURCE)
right = PandasTransformation(udf=rehydrated, udf_string=_UDF_SOURCE)
assert left == right

different = PandasTransformation(udf=rehydrated, udf_string=_UDF_SOURCE + "\n")
assert left != different


def test_python_transformation_eq_uses_udf_string_not_bytecode():
rehydrated = resolve_udf(udf_string=_UDF_SOURCE, preferred_name="pandas_udf")
left = PythonTransformation(udf=pandas_udf, udf_string=_UDF_SOURCE)
right = PythonTransformation(udf=rehydrated, udf_string=_UDF_SOURCE)
assert left == right
assert left != PythonTransformation(udf=rehydrated, udf_string="other")
Loading