diff --git a/sdk/python/feast/infra/registry/registry.py b/sdk/python/feast/infra/registry/registry.py index baa8620140e..a6a19a3457e 100644 --- a/sdk/python/feast/infra/registry/registry.py +++ b/sdk/python/feast/infra/registry/registry.py @@ -53,6 +53,7 @@ from feast.permissions.permission import Permission from feast.project import Project from feast.project_metadata import ProjectMetadata +from feast.proto_utils import serialize_data_source from feast.protos.feast.core.FeatureViewVersion_pb2 import FeatureViewVersionRecord from feast.protos.feast.core.Registry_pb2 import Registry as RegistryProto from feast.repo_config import RegistryConfig @@ -685,6 +686,13 @@ def _update_metadata_fields( existing_proto.spec.stream_source.CopyFrom( updated_fv.stream_source.to_proto() ) + # LabelViewSpec has a single optional `source` field instead + if isinstance(updated_fv, LabelView): + source_proto = serialize_data_source(updated_fv.source) + if source_proto is not None: + existing_proto.spec.source.CopyFrom(source_proto) + else: + existing_proto.spec.ClearField("source") # Update or clear version pin if hasattr(existing_proto.meta, "current_version_number") and hasattr( diff --git a/sdk/python/tests/unit/infra/registry/test_update_metadata_fields.py b/sdk/python/tests/unit/infra/registry/test_update_metadata_fields.py index 60b6ed165cc..6e7879f8850 100644 --- a/sdk/python/tests/unit/infra/registry/test_update_metadata_fields.py +++ b/sdk/python/tests/unit/infra/registry/test_update_metadata_fields.py @@ -1,6 +1,6 @@ -"""Unit tests for Registry._update_metadata_fields TTL handling (issue #6703). +"""Unit tests for Registry._update_metadata_fields. -Re-applying a FeatureView with its ttl cleared to ``None`` or +TTL handling (issue #6703): re-applying a FeatureView with its ttl cleared to ``None`` or ``timedelta(0)`` (both the documented ways to express "no ttl") used to be silently dropped, because the update was gated on ``updated_fv.ttl`` being truthy -- and both of those values are falsy. @@ -13,12 +13,14 @@ import pytest +from feast.data_source import PushSource from feast.entity import Entity from feast.feature_view import FeatureView from feast.field import Field from feast.infra.offline_stores.file_source import FileSource from feast.infra.registry.registry import Registry -from feast.types import Float32 +from feast.labeling.label_view import LabelView +from feast.types import Float32, String def _feature_view(ttl): @@ -51,3 +53,45 @@ def test_update_metadata_fields_preserves_finite_ttl(): Registry._update_metadata_fields(None, existing_proto, updated_fv) assert existing_proto.spec.ttl.ToTimedelta() == timedelta(days=3) + + +def _label_view(source): + return LabelView( + name="lv", + entities=[Entity(name="e", join_keys=["e_id"])], + schema=[ + Field(name="label", dtype=String), + Field(name="labeler", dtype=String), + ], + source=source, + ) + + +def _file_source(path): + return FileSource(name="labels", path=path, timestamp_field="ts_col") + + +@pytest.mark.parametrize( + "make_source", + [ + _file_source, + lambda path: PushSource(name="push", batch_source=_file_source(path)), + ], + ids=["file_source", "push_source"], +) +def test_update_metadata_fields_updates_label_view_source(make_source): + existing_proto = _label_view(make_source("file://old/*")).to_proto() + + updated = _label_view(make_source("file://new/*")) + Registry._update_metadata_fields(None, existing_proto, updated) + + assert existing_proto.spec.source == updated.to_proto().spec.source + assert LabelView.from_proto(existing_proto).source == updated.source + + +def test_update_metadata_fields_clears_label_view_source(): + existing_proto = _label_view(_file_source("file://old/*")).to_proto() + + Registry._update_metadata_fields(None, existing_proto, _label_view(None)) + + assert not existing_proto.spec.HasField("source")