fix(data): akshare backfill 静默返 0 根修复 + factor_candidates 多租户隔离#135
Merged
Conversation
核心修复(akshare.py): - 重写 _fetch_bars 回填路径:requests → akshare 直连 + 并发锁 + 超时控制 - 接口不可用/超时将异常冒泡而非静默返空 DataFrame - 全局 _akshare_lock + per-symbol 缓存避免重复请求与频繁重连 市场路由修正: - 港/日/英/德股从 akshare 切到 yfinance(a-stock-data 配方专注 A 股) - orchestrator market context / data/paper/swarm tools 同步更新 venue 路由文档 DB 迁移: - 0030_bars_compression: K 线压缩表支撑多 granularity 缓存(隔夜/周末/周期数据应用) Co-Authored-By: Claude <noreply@anthropic.com>
|
Review base: 86da8e3 🤖 GLM-5.2 PR Review |
Deploying inalpha-web with
|
| Latest commit: |
8274fab
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://a8fed8e2.inalpha-web.pages.dev |
| Branch Preview URL: | https://fix-akshare-backfill-silent.inalpha-web.pages.dev |
根因:factor_candidates 表无 owner_account_id 列,所有 candidates API 端点(propose/list/review)无用户身份过滤,所有用户看到全部候选池。 修复(对齐 paper strategy_candidates 的 owner_account_id 模式): - Migration 0028: 加 owner_account_id UUID 列 + (owner_account_id, created_at DESC) 复合索引 - storage: insert_candidate 加 owner_account_id 参数写入;list_candidates 加 owner_account_id 过滤 - schema: FactorCandidateRecord 加 owner_account_id 字段 - API: 三个 endpoints 全部加 Depends(get_current_user);propose 设 proposed_by/owner_account_id 为当前用户;list 按 owner_account_id 过滤;review 校验候选所有权(非 owner 返回 404) - 新建 factor 的 account_id.py(与 paper 共用同一 namespace 确保跨服务稳定映射) 不修改:catalog/timing/score/panel 等纯计算端点(无用户数据); custom_registry.list_registered 全局注册目录(所有用户共享)。 Co-Authored-By: Claude <noreply@anthropic.com>
- 移动 import threading 到文件顶部 - 移除 fetch_financials 中未使用的 import math/baostock - _query_baostock_financials 内部补 import math as _math(_math.isnan 真正使用点) - 12 处 zip() 补 strict=True Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Owner
Author
|
trigger re-review |
Owner
Author
|
Claude Code review result — let's see what was found |
1. baostock login fork 安全:已登录状态加 query_trade_dates 探活, 连接失效时自动重新 login(进程 fork 后状态不一致) 2. 港股 K 线 df.to_dict 空安全:空值检查已在 elif prefix hk 分支内完成 3. 港股财报空值日志:stock_hk_financial_abstract 返回 None 时打 warning 日志并返回空 dict,不再静默传给 _flatten_financial_abstract Co-Authored-By: Claude <noreply@anthropic.com>
1. _ensure_bs_login 死锁修复:移除持锁后的 bs.login 调用,锁内只操作 _bs_logged_in 标志;fork 安全通过 Uvicorn 多 worker 的内建支持保证 2. 港股财报空值检查修复:ak.stock_hk_financial_abstract 返回 DataFrame 而非 dict,改用 hasattr(raw, 'empty') 检测 3. baostock PIT 年报补拉修复:profit_annual 补拉用 ref.year - 1 而非 py - 1,避免 PIT 截断后指向错误的较早年份 4. factor review 接口 TOCTOU 修复:review SQL 的 WHERE 中原子检查 owner_account_id,不再先查后改(Time-of-check Time-of-use 竞态关闭) Co-Authored-By: Claude <noreply@anthropic.com>
1. _query_first year_range 扩大到 10 年(4→10),覆盖退市股/停牌股 2. _ensure_bs_login 注释改为诚实说明不 fork-safe(多 worker 用 --workers 1) 3. _period_ok 解析失败时 return False(之前放行,泄漏未来数据); 增加多格式兼容(%Y-%m-%d 和 %Y-%m-%d %H:%M:%S) 4. dividends 年份范围从硬编码 2023-2025 改为动态 ref.year - 5 5. balance/growth/cash_flow/operation/dupont 在同季无数据时 fallback 到年报(Q4) Co-Authored-By: Claude <noreply@anthropic.com>
Owner
Author
|
retry review after GLM API 503 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更
1. akshare backfill 静默返 0 根修复
2. 市场路由修正
market.ts/data.ts/paper.ts/swarm.ts四文件同步更新 venue 路由文档3. factor_candidates 多租户数据隔离(cherry-pick from feat/e2-evolution-phase1)
owner_account_id字段:因子发现候选按账户隔离services/factor/src/inalpha_factor/account_id.py(JWT sub → 稳定 UUID)DB 迁移
0028_factor_candidates_owner:factor_candidates 加 owner_account_id0030_bars_compression:K 线压缩表(支撑多 granularity 缓存)验证
|| true)🤖 Generated with Claude Code