File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -872,6 +872,14 @@ def _load_sync_fundamental_sources(
872872 return None , None
873873
874874
875+ def _stringify_report_strategy_value (value : Any ) -> Optional [str ]:
876+ if value is None :
877+ return None
878+ if isinstance (value , str ):
879+ return value
880+ return str (value )
881+
882+
875883def _build_analysis_report (
876884 report_data : Dict [str , Any ],
877885 query_id : str ,
@@ -932,10 +940,10 @@ def _build_analysis_report(
932940 strategy = None
933941 if strategy_data :
934942 strategy = ReportStrategy (
935- ideal_buy = strategy_data .get ("ideal_buy" ),
936- secondary_buy = strategy_data .get ("secondary_buy" ),
937- stop_loss = strategy_data .get ("stop_loss" ),
938- take_profit = strategy_data .get ("take_profit" )
943+ ideal_buy = _stringify_report_strategy_value ( strategy_data .get ("ideal_buy" ) ),
944+ secondary_buy = _stringify_report_strategy_value ( strategy_data .get ("secondary_buy" ) ),
945+ stop_loss = _stringify_report_strategy_value ( strategy_data .get ("stop_loss" ) ),
946+ take_profit = _stringify_report_strategy_value ( strategy_data .get ("take_profit" ) )
939947 )
940948
941949 extracted_fundamental = extract_fundamental_detail_fields (
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
3232- [ 新功能] 通知网关新增默认关闭的进程内降噪配置,支持去重、冷却、静默时段和最低严重级别,并将每日摘要开关标记为预留能力。
3333- [ 文档] 恢复多语言 README 新闻源配置表中推荐项的加粗样式,统一相关项目章节层级,并精简顶部导航、联系文案和尾部展示。
3434- [ 修复] Docker 挂载的 ` logs ` 目录不可写时启动日志自动降级到控制台输出,并补充非 root 容器目录权限说明。
35+ - [ 修复] 修正分析报告 API 构建策略点位时数值字段未归一为字符串的问题,避免策略价格触发响应 DTO 类型校验失败。
3536
3637## [ 3.16.0] - 2026-05-10
3738
Original file line number Diff line number Diff line change @@ -638,6 +638,34 @@ def test_build_analysis_report_extracts_fundamental_fields_from_snapshot(self) -
638638 self .assertEqual (report .details .financial_report ["report_date" ], "2025-12-31" )
639639 self .assertEqual (report .details .dividend_metrics ["ttm_dividend_yield_pct" ], 2.5 )
640640
641+ def test_build_analysis_report_stringifies_strategy_price_fields (self ) -> None :
642+ if _build_analysis_report is None :
643+ self .skipTest ("analysis endpoint helpers unavailable in this environment" )
644+
645+ report = _build_analysis_report (
646+ report_data = {
647+ "meta" : {},
648+ "summary" : {},
649+ "strategy" : {
650+ "ideal_buy" : 10.0 ,
651+ "secondary_buy" : None ,
652+ "stop_loss" : 9.5 ,
653+ "take_profit" : 11.6 ,
654+ },
655+ "details" : {},
656+ },
657+ query_id = "q1" ,
658+ stock_code = "600519" ,
659+ stock_name = "贵州茅台" ,
660+ context_snapshot = None ,
661+ fallback_fundamental_payload = None ,
662+ )
663+
664+ self .assertEqual (report .strategy .ideal_buy , "10.0" )
665+ self .assertIsNone (report .strategy .secondary_buy )
666+ self .assertEqual (report .strategy .stop_loss , "9.5" )
667+ self .assertEqual (report .strategy .take_profit , "11.6" )
668+
641669 def test_build_analysis_report_extracts_related_board_fields_from_snapshot (self ) -> None :
642670 if _build_analysis_report is None :
643671 self .skipTest ("analysis endpoint helpers unavailable in this environment" )
You can’t perform that action at this time.
0 commit comments