Skip to content

Commit 8fdcee7

Browse files
fix: Log ODFV materialization skips instead of printing them (#7117)
_materialize_odfv gives up on five conditions and returns without materializing. Each one printed to stdout with a hand-rolled [WARNING] prefix, so a user's logging configuration could not silence, redirect or capture it. The module already has _logger and uses it for every other warning. Signed-off-by: VenishPaneliya <[email protected]> Co-authored-by: Shuchu Han <[email protected]>
1 parent 0811002 commit 8fdcee7

2 files changed

Lines changed: 48 additions & 10 deletions

File tree

‎sdk/python/feast/feature_store.py‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,8 +2404,9 @@ def _materialize_odfv(
24042404
):
24052405
"""Helper to materialize a single OnDemandFeatureView."""
24062406
if not feature_view.source_feature_view_projections:
2407-
print(
2408-
f"[WARNING] ODFV {feature_view.name} materialization: No source feature views found."
2407+
_logger.warning(
2408+
"ODFV %s materialization: No source feature views found.",
2409+
feature_view.name,
24092410
)
24102411
return
24112412
start_date = utils.make_tzaware(start_date)
@@ -2432,20 +2433,27 @@ def _materialize_odfv(
24322433
all_join_keys = {key for key in all_join_keys if key}
24332434

24342435
if not all_join_keys:
2435-
print(
2436-
f"[WARNING] ODFV {feature_view.name} materialization: No join keys found in source views. Cannot create entity_df. Skipping."
2436+
_logger.warning(
2437+
"ODFV %s materialization: No join keys found in source views. "
2438+
"Cannot create entity_df. Skipping.",
2439+
feature_view.name,
24372440
)
24382441
return
24392442

24402443
if len(entity_timestamp_col_names) > 1:
2441-
print(
2442-
f"[WARNING] ODFV {feature_view.name} materialization: Found multiple timestamp columns in sources ({entity_timestamp_col_names}). This is not supported. Skipping."
2444+
_logger.warning(
2445+
"ODFV %s materialization: Found multiple timestamp columns in "
2446+
"sources (%s). This is not supported. Skipping.",
2447+
feature_view.name,
2448+
entity_timestamp_col_names,
24432449
)
24442450
return
24452451

24462452
if not entity_timestamp_col_names:
2447-
print(
2448-
f"[WARNING] ODFV {feature_view.name} materialization: No batch sources with timestamp columns found for sources. Skipping."
2453+
_logger.warning(
2454+
"ODFV %s materialization: No batch sources with timestamp "
2455+
"columns found for sources. Skipping.",
2456+
feature_view.name,
24492457
)
24502458
return
24512459

@@ -2474,8 +2482,10 @@ def _materialize_odfv(
24742482
all_source_dfs.append(df)
24752483

24762484
if not all_source_dfs:
2477-
print(
2478-
f"No source data found for ODFV {feature_view.name} in the given time range. Skipping materialization."
2485+
_logger.warning(
2486+
"No source data found for ODFV %s in the given time range. "
2487+
"Skipping materialization.",
2488+
feature_view.name,
24792489
)
24802490
return
24812491

‎sdk/python/tests/unit/test_unit_feature_store.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import logging
12
from dataclasses import dataclass
3+
from datetime import datetime
24
from typing import Dict, List
35
from unittest.mock import MagicMock, patch
46

@@ -181,3 +183,29 @@ def test_write_to_offline_store_resolves_feature_view_with_single_lookup():
181183
registry.get_label_view.assert_not_called()
182184

183185
provider.ingest_df_to_offline_store.assert_called_once()
186+
187+
188+
def test_materialize_odfv_reports_skips_through_the_logger(caplog, capsys):
189+
"""``_materialize_odfv`` must report a skipped materialization via the logger.
190+
191+
The method gives up on five different conditions and returns without materializing
192+
anything. Those messages went to stdout with a hand-rolled ``[WARNING]`` prefix, so a
193+
user's logging configuration could not silence, redirect or capture them, and nothing
194+
about the skip reached the log.
195+
"""
196+
store = FeatureStore.__new__(FeatureStore)
197+
198+
feature_view = MagicMock()
199+
feature_view.name = "driver_hourly_stats_odfv"
200+
feature_view.source_feature_view_projections = {}
201+
202+
with caplog.at_level(logging.WARNING, logger="feast.feature_store"):
203+
store._materialize_odfv(
204+
feature_view,
205+
start_date=datetime(2024, 1, 1),
206+
end_date=datetime(2024, 1, 2),
207+
full_feature_names=False,
208+
)
209+
210+
assert "No source feature views found" in caplog.text
211+
assert capsys.readouterr().out == ""

0 commit comments

Comments
 (0)