Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions autowsgr/server/routes/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ def executor(task_info: Any) -> list[dict[str, Any]]:
else:
raise ValueError('必须提供 plan 或 plan_id')

# 允许 plan_id + plan 覆盖: 前端可在不改 YAML 的情况下动态指定舰队与舰船名单。
request_plan = request.plan
override_fleet_id = request_plan.fleet_id if request_plan is not None else None
override_fleet = request_plan.fleet if request_plan is not None else None
Comment on lines +111 to +113
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CombatPlanRequest.fleet_id has a default of 1 (non-optional). When the client sends plan_id + a partial plan only to override fleet (or other fields), request_plan.fleet_id will still be 1, so this will unintentionally override the YAML plan’s fleet_id to 1 by passing fleet_id=override_fleet_id into run_normal_fight. Consider treating fleet overrides as “only if explicitly provided”, e.g. derive overrides from request_plan.model_fields_set / exclude_unset=True and pass fleet_id=None unless fleet_id was actually included in the request payload.

Suggested change
request_plan = request.plan
override_fleet_id = request_plan.fleet_id if request_plan is not None else None
override_fleet = request_plan.fleet if request_plan is not None else None
# 仅在请求中显式提供对应字段时才覆盖,避免 Pydantic 默认值意外覆盖 YAML 配置。
request_plan = request.plan
request_plan_fields = (
getattr(request_plan, 'model_fields_set', None)
or getattr(request_plan, '__fields_set__', set())
if request_plan is not None
else set()
)
override_fleet_id = (
request_plan.fleet_id
if request_plan is not None and 'fleet_id' in request_plan_fields
else None
)
override_fleet = (
request_plan.fleet
if request_plan is not None and 'fleet' in request_plan_fields
else None
)

Copilot uses AI. Check for mistakes.

for i in range(request.times):
if task_manager.should_stop():
break
Expand All @@ -115,7 +120,13 @@ def executor(task_info: Any) -> list[dict[str, Any]]:
_log.info('[Task] 常规战第 {}/{} 轮', i + 1, request.times)

try:
result = run_normal_fight(ctx, plan, times=1)[0]
result = run_normal_fight(
ctx,
plan,
times=1,
fleet_id=override_fleet_id,
fleet=override_fleet,
)[0]
results.append(convert_combat_result(result, i + 1))
task_manager.add_result(results[-1])
except Exception as e:
Expand Down Expand Up @@ -152,7 +163,15 @@ def executor(task_info: Any) -> list[dict[str, Any]]:
else:
raise ValueError('必须提供 plan 或 plan_id')

fleet_id = request.fleet_id or plan.fleet_id
request_plan = request.plan
override_fleet = request_plan.fleet if request_plan is not None else None
# 优先级: 顶层 fleet_id > plan 覆盖 fleet_id > YAML 内 fleet_id
if request.fleet_id is not None:
fleet_id = request.fleet_id
elif request_plan is not None and request_plan.fleet_id is not None:
Comment on lines +168 to +171
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because CombatPlanRequest.fleet_id is a non-optional field with default 1, the condition request_plan is not None and request_plan.fleet_id is not None will be true whenever request.plan is present. That means sending plan_id + a partial plan (e.g. only fleet) will force fleet_id to 1 and ignore the YAML’s plan.fleet_id. To avoid accidental overrides, only treat request_plan.fleet_id as an override when it was explicitly set in the incoming JSON (e.g. check request_plan.model_fields_set or use a dict built with exclude_unset=True).

Suggested change
# 优先级: 顶层 fleet_id > plan 覆盖 fleet_id > YAML 内 fleet_id
if request.fleet_id is not None:
fleet_id = request.fleet_id
elif request_plan is not None and request_plan.fleet_id is not None:
plan_fleet_id_is_set = request_plan is not None and 'fleet_id' in request_plan.model_fields_set
# 优先级: 顶层 fleet_id > plan 显式覆盖 fleet_id > YAML 内 fleet_id
if request.fleet_id is not None:
fleet_id = request.fleet_id
elif plan_fleet_id_is_set:

Copilot uses AI. Check for mistakes.
fleet_id = request_plan.fleet_id
else:
fleet_id = plan.fleet_id

for i in range(request.times):
if task_manager.should_stop():
Expand All @@ -162,7 +181,13 @@ def executor(task_info: Any) -> list[dict[str, Any]]:
_log.info('[Task] 活动战第 {}/{} 轮', i + 1, request.times)

try:
result = run_event_fight(ctx, plan, times=1, fleet_id=fleet_id)[0]
result = run_event_fight(
ctx,
plan,
times=1,
fleet_id=fleet_id,
fleet=override_fleet,
)[0]
results.append(convert_combat_result(result, i + 1))
task_manager.add_result(results[-1])
except Exception as e:
Expand Down