取论断的查询补确定排序:计划本该是可复现的

原来这条查询没有 ORDER BY,而它的文档串写着「每票取最近披露日的最多三条」——
代码却按数据库返回的天然顺序截前几条。没有排序时那个顺序不保证,于是同一个数据日、
同一份代码,相隔三十二秒的两次装配,候选卡与逻辑线有五处不一样。

实测证据:连续两次 collect,main.card 差 5 处、main.logic 差 5 处、card_rank 差 20 处、
顶层的候选单与关注名单也不一样。计划因此不可复现,下游也不知道自己拿的是哪一份。

按票、披露日倒序、论断编号三级排序。编号做次级排序是因为光按披露日排,同一天的多条
之间仍然没有定序。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
zlt 2026-09-10 09:36:53 +08:00
parent 7ce2484abe
commit 548990180d
1 changed files with 2 additions and 1 deletions

View File

@ -256,7 +256,8 @@ def logic_claims(codes, ds: str, per_stock: int | None = None, read_pg=None) ->
marks = ",".join(["%s"] * len(dots))
rows = _records(reader(
f"SELECT {', '.join(_LOGIC_COLS)} FROM v_factor_logic "
f"WHERE ts_code IN ({marks}) AND disclosure_date <= %s",
f"WHERE ts_code IN ({marks}) AND disclosure_date <= %s "
f"ORDER BY ts_code, disclosure_date DESC, claim_id",
tuple(dots) + (ds,)))
except Exception as e: # noqa: BLE001
print(f" (因果论断视图 v_factor_logic 读取失败,候选卡的论断证据线整体缺席: {e!r}")