fix(data): ak-weekly 断路器饿死修复=_safe_northbound_em+类型调序 [vps]——09-05 03:00 首跑 rc=2 根因:akshare stock_hsgt_individual_em 对无北向数据标的(~1117/2883,301xxx 等)在 data_json[result][pages] 抛 TypeError NoneType not subscriptable→failed→30 连败断路器→跳过后续类型,share_capital/top_holders/gdhs 全饿死(gdhs 目录至今不存在);端点健康(600519 返 1683 行,09-06 晨复测);修=①_safe_northbound_em 子串匹配 not subscriptable 返空 df 带 9 列 schema→走无北向持仓 empty 写空+done 既定语义不耗重试/断路器(同 _safe_top_10_em 手法)②weekly wrapper 调序 gdhs,share_capital,top_holders,northbound 最大最险者殿后防再连累③顺手 BOM;TDD 2 新测先红后绿+217 全绿;双脚本已 scp 生效位+Parse/py_compile 预检过;gdhs 手动补跑另行 [vps]
CI/CD / test (push) Successful in 23s
CI/CD / nas-deploy (push) Successful in 7s
CI/CD / nas-verify (push) Successful in 13s

This commit is contained in:
2026-09-06 08:29:58 +08:00
parent c728f2368c
commit 694a0d2238
3 changed files with 73 additions and 5 deletions
@@ -9,6 +9,7 @@
import argparse
import pandas as pd
import pytest
import akshare_static_download as mod # noqa: E402 (conftest 已加 sys.path)
@@ -205,3 +206,34 @@ class TestHotAndGdhsFamily:
ids = [u[0] for u in units]
assert "20250930_gdhs" in ids
assert "20251231_gdhs" not in ids
# ======================== ③ northbound 无数据崩溃安全包装 ========================
class TestSafeNorthbound:
"""_safe_northbound_em (2026-09-05 ak-weekly 断路器事故修复)。
akshare stock_hsgt_individual_em 对无北向数据标的 (301xxx 等) 在
data_json["result"]["pages"] 处抛 TypeError(NoneType not subscriptable)
—— 周六实测 2883 股中 1117 连败, 末段 30 连败触发断路器 rc=2,
饿死后续 share_capital/top_holders/gdhs (gdhs 目录至今不存在)。
端点本身健康 (600519 正常返 1683 行, 09-06 晨复测)。
确定性无数据 → 空 df 带 schema → 「无北向持仓」empty 写空+done
(脚本头部既定语义), 不消耗重试/断路器配额 (同 _safe_top_10_em 手法)。
"""
def test_no_data_crash_returns_empty_with_schema(self, monkeypatch):
def boom(symbol):
raise TypeError("'NoneType' object is not subscriptable")
monkeypatch.setattr(mod.ak, "stock_hsgt_individual_em", boom)
df = mod._safe_northbound_em("301638")
assert df.empty
assert list(df.columns) == mod.NORTHBOUND_COLUMNS
def test_other_typeerror_propagates(self, monkeypatch):
"""非无数据签名的 TypeError 透传 (走 call_ak_with_retry 重试)。"""
def boom(symbol):
raise TypeError("connection reset by peer")
monkeypatch.setattr(mod.ak, "stock_hsgt_individual_em", boom)
with pytest.raises(TypeError):
mod._safe_northbound_em("301638")