From c227bb40789c4352badf805779a3c122479a8e01 Mon Sep 17 00:00:00 2001 From: OoO Date: Wed, 13 May 2026 12:49:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A3=9C=E7=AB=B6=E5=93=81=20Feeder=20?= =?UTF-8?q?=E6=90=9C=E5=B0=8B=E8=A9=9E=20fallback=20=E8=A8=BA=E6=96=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/competitor_price_feeder.py | 6 +++++- ...est_competitor_match_attempts_persistence.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/services/competitor_price_feeder.py b/services/competitor_price_feeder.py index 2b0acdd..cc79e39 100644 --- a/services/competitor_price_feeder.py +++ b/services/competitor_price_feeder.py @@ -145,7 +145,11 @@ def _build_search_keywords(momo_name: str) -> list: elif parsed.keywords: terms.append(" ".join(parsed.keywords[:4])) except Exception: - pass + logger.debug( + "[Feeder] ProductNameParser failed while building search keywords; " + "fallback to cleaned product name", + exc_info=True, + ) return _dedupe_terms(terms) diff --git a/tests/test_competitor_match_attempts_persistence.py b/tests/test_competitor_match_attempts_persistence.py index 038524f..bd042a0 100644 --- a/tests/test_competitor_match_attempts_persistence.py +++ b/tests/test_competitor_match_attempts_persistence.py @@ -1,4 +1,5 @@ from pathlib import Path +import logging ROOT = Path(__file__).resolve().parents[1] @@ -26,3 +27,19 @@ def test_competitor_feeder_persists_all_match_attempt_outcomes(): assert "best_match_score" in migration assert "error_message" in migration assert "idx_comp_match_attempts_sku_source_time" in migration + + +def test_competitor_feeder_logs_keyword_parser_fallback(monkeypatch, caplog): + from services import competitor_price_feeder + from services.price_comparison import ProductNameParser + + def broken_parse(self, *_args, **_kwargs): + raise RuntimeError("parser unavailable") + + monkeypatch.setattr(ProductNameParser, "parse", broken_parse) + caplog.set_level(logging.DEBUG, logger="services.competitor_price_feeder") + + terms = competitor_price_feeder._build_search_keywords("理膚寶水 B5 修復霜 40ml") + + assert terms + assert "fallback to cleaned product name" in caplog.text