Skip to content

Commit 970b048

Browse files
author
saket3395
committed
test: cover ttl clearing in _update_metadata_fields (#6703)
Adds unit coverage requested in review: - clearing a finite ttl to None or timedelta(0) now writes a zero Duration (previously silently dropped) - a finite-to-finite ttl update is preserved _update_metadata_fields uses no instance state, so it is exercised directly via the class, mirroring the FeatureView/FileSource/Field construction used elsewhere in the unit tests.
1 parent 0d1472e commit 970b048

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""Unit tests for Registry._update_metadata_fields TTL handling (issue #6703).
2+
3+
Re-applying a FeatureView with its ttl cleared to ``None`` or
4+
``timedelta(0)`` (both the documented ways to express "no ttl") used to be
5+
silently dropped, because the update was gated on ``updated_fv.ttl`` being
6+
truthy -- and both of those values are falsy.
7+
8+
``_update_metadata_fields`` does not use any instance state, so it is exercised
9+
directly via the class here rather than standing up a full registry backend.
10+
"""
11+
12+
from datetime import timedelta
13+
14+
import pytest
15+
16+
from feast.entity import Entity
17+
from feast.feature_view import FeatureView
18+
from feast.field import Field
19+
from feast.infra.offline_stores.file_source import FileSource
20+
from feast.infra.registry.registry import Registry
21+
from feast.types import Float32
22+
23+
24+
def _feature_view(ttl):
25+
return FeatureView(
26+
name="fv",
27+
entities=[Entity(name="e", join_keys=["e_id"])],
28+
schema=[Field(name="f1", dtype=Float32)],
29+
source=FileSource(path="file://feast/*", timestamp_field="ts_col"),
30+
ttl=ttl,
31+
)
32+
33+
34+
@pytest.mark.parametrize("cleared_ttl", [None, timedelta(0)])
35+
def test_update_metadata_fields_clears_ttl(cleared_ttl):
36+
existing_proto = _feature_view(timedelta(days=10)).to_proto()
37+
# sanity: the existing view starts with a finite ttl
38+
assert existing_proto.spec.ttl.ToNanoseconds() != 0
39+
40+
updated_fv = _feature_view(cleared_ttl)
41+
Registry._update_metadata_fields(None, existing_proto, updated_fv)
42+
43+
# the cleared ttl (None / timedelta(0)) must now be reflected as "no ttl"
44+
assert existing_proto.spec.ttl.ToNanoseconds() == 0
45+
46+
47+
def test_update_metadata_fields_preserves_finite_ttl():
48+
existing_proto = _feature_view(timedelta(days=10)).to_proto()
49+
50+
updated_fv = _feature_view(timedelta(days=3))
51+
Registry._update_metadata_fields(None, existing_proto, updated_fv)
52+
53+
assert existing_proto.spec.ttl.ToTimedelta() == timedelta(days=3)

0 commit comments

Comments
 (0)