fix(server): forward plan fleet overrides for task routes#397
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the task execution routes to forward “fleet overrides” from the request into the underlying combat runners, enabling the frontend to dynamically override fleet selection without modifying YAML plans.
Changes:
- Forward
fleet_id/fleetoverrides intorun_normal_fight. - Add fleet override forwarding into
run_event_fight, with an explicit fleet_id precedence rule.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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 |
There was a problem hiding this comment.
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.
| 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 | |
| ) |
| # 优先级: 顶层 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: |
There was a problem hiding this comment.
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).
| # 优先级: 顶层 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: |
No description provided.