Skip to content

fix(dataflows): 修复 _get_tushare_stock_info 缺失导致 Tushare 备用数据源永久失效#703

Open
sliangliang wants to merge 1 commit into
hsliuping:mainfrom
sliangliang:fix/tushare-stock-info-fallback
Open

fix(dataflows): 修复 _get_tushare_stock_info 缺失导致 Tushare 备用数据源永久失效#703
sliangliang wants to merge 1 commit into
hsliuping:mainfrom
sliangliang:fix/tushare-stock-info-fallback

Conversation

@sliangliang

Copy link
Copy Markdown

问题描述

DataSourceManager._try_fallback_stock_info() (data_source_manager.py:1616) 调用了 self._get_tushare_stock_info(symbol),但这个方法在类里从未实现,导致:

❌ [Tushare] 获取股票信息失败:
   'DataSourceManager' object has no attribute '_get_tushare_stock_info'
❌ 备用数据源 ChinaDataSource.TUSHARE 失败:
   'DataSourceManager' object has no attribute '_get_tushare_stock_info'

影响:当默认数据源(如 AKShare)失败、降级到备用源时,Tushare 这一档永远进不去,即便用户配置了有效的 TUSHARE_TOKEN 也用不上 → 总是降级到 BaoStock 兜底 → 部分公司基本信息(行业、上市日期等)不准。

复现

  1. DEFAULT_CHINA_DATA_SOURCE=akshare(默认)
  2. AKShare 偶发网络问题(Connection aborted
  3. 系统进入 _try_fallback_stock_info 流程
  4. 遍历到 Tushare → AttributeError → 跳过 → 最终用 BaoStock

修复

_get_akshare_stock_info 之前补上缺失的方法实现。

关键设计

  • 直接调 provider.api.stock_basic()(同步接口),不调 interface.get_china_stock_info_tushare() —— 因为后者会回调本方法,造成无限递归
  • 返回 dict 结构与 _get_akshare_stock_info / _get_baostock_stock_info 保持一致
  • 失败时返回 {'source': 'tushare_failed'} 等明确的 source 标签,便于上层识别

注:原作者在 docs/development/CIRCULAR_CALL_ANALYSIS.mddocs/integration/data-sources/DATA_SOURCE_MANAGER_ENHANCEMENT.md 中都提到过这个方法(且文档说"已修复循环调用 ✅"),但实际代码没有实现。

验证

mgr = DataSourceManager()
# 修复前
mgr._get_tushare_stock_info("688008")
# AttributeError: 'DataSourceManager' object has no attribute '_get_tushare_stock_info'

# 修复后
mgr._get_tushare_stock_info("688008")
# {'symbol': '688008', 'name': '澜起科技', 'industry': '半导体', 'source': 'tushare', ...}
mgr._get_tushare_stock_info("300059")
# {'symbol': '300059', 'name': '东方财富', 'industry': '证券', 'source': 'tushare', ...}
mgr._get_tushare_stock_info("601390")
# {'symbol': '601390', 'name': '中国中铁', 'industry': '建筑工程', 'source': 'tushare', ...}

类型

  • Bug fix (no breaking changes)

影响范围

  • 修复了 _try_fallback_stock_info() 的 Tushare 分支
  • 不改变默认数据源行为
  • 不影响 K 线/财务/新闻等其他数据获取路径

The _try_fallback_stock_info() at line 1616 calls
self._get_tushare_stock_info(symbol) but this method was never
defined on DataSourceManager, causing AttributeError every time
Tushare is reached as a fallback source. Effect: Tushare's stock
info API is permanently unreachable in fallback path, even with
a valid TUSHARE_TOKEN configured.

Symptoms in logs:
  ❌ [Tushare] 获取股票信息失败:
    'DataSourceManager' object has no attribute
    '_get_tushare_stock_info'

This was the missing implementation referenced (and assumed
to exist) in docs/development/CIRCULAR_CALL_ANALYSIS.md and
docs/integration/data-sources/DATA_SOURCE_MANAGER_ENHANCEMENT.md.

Implementation notes:
  - Calls provider.api.stock_basic() directly (sync), avoids the
    interface.get_china_stock_info_tushare() function which would
    call back into this method and cause infinite recursion.
  - Returns the same dict shape used by _get_akshare_stock_info /
    _get_baostock_stock_info for consistency.

Verified: Tushare branch now returns real stock names (e.g.
688008 → 澜起科技 / 半导体) instead of falling through to
BaoStock as the final fallback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant