fix(report): 空的任务集合被当成了「不限制平台」,导致报表串平台数据
现象:切到抖音,报表里显示的是小红书的数据。
根因是报告聚合里的一行真值判断:
scope = list(task_ids) if task_ids else None
空列表是假值,而空列表在这里的含义是「这个平台一个任务都没有」,不是「不限制平台」。
于是 platform=dy 且抖音还没有任务时,_resolve_scope 返回的 [] 被翻译成了 None,
聚合范围从「抖音的任务」变成了**全部任务** —— 小红书的数字就这么显示在了抖音页面上。
顺带 task_ids 也回成 None,界面会显示成「全部任务」。
改成 `is not None`。空列表进去就让 in_([]) 恒假,结果为空,这才是对的。
排查时把所有同类写法过了一遍,只有这一处错,其余(service.py 的 10 处作用域judgement、
_resolve_scope、export)用的都是 `is not None`。
测试:新增两条,并且**验证过它们在修复前会红**(失败信息就是 assert 42 == 0 ——
查一个没有任何任务的平台,却返回了小红书那条作品的 42 个赞)。
同时修掉一条空跑的测试:test_a_platform_with_no_tasks_yields_empty_not_everything
原先种了任务却没有作品/指标数据,于是过滤生效与否结果都是 0,什么都测不出来 ——
这正是这个 bug 能活下来的原因。现在它会真的塞一条作品+快照进去,并在末尾断言
「小红书自己的报表看得到那条数据」,用来证明前面那两个 0 是过滤出来的而不是没数据。
This commit is contained in:
@@ -135,7 +135,11 @@ async def build_report(
|
||||
start_ms, _ = day_bounds(start_day)
|
||||
_, end_ms = day_bounds(end_day)
|
||||
|
||||
scope = list(task_ids) if task_ids else None
|
||||
# 必须是 `is not None`,不能写 `if task_ids` —— **空列表是假值**,而空列表在这里
|
||||
# 的含义是「这个平台一个任务都没有」,不是「不限制平台」。用真值判断的话,
|
||||
# 切到一个还没有任务的平台,报表会把**所有**任务的数据聚合出来(看起来就是
|
||||
# 「抖音的报表里全是小红书的数据」)。
|
||||
scope = list(task_ids) if task_ids is not None else None
|
||||
days = iter_days(start_day, end_day)
|
||||
|
||||
# Fetch every snapshot up to the range end: the delta on the first day needs
|
||||
|
||||
Reference in New Issue
Block a user