from typing import Optional, Union, List from pydantic import BaseModel, model_validator, PrivateAttr class ExportRequest(BaseModel): # uuid which maps to a specific export request, used for tracking and logging task_id: Union[str, None] # uuid which maps to a specific export operation, used for tracking and logging. subtask is the child of the # task, where the work has been distributed across workers subtask_id: Union[str, None] # associated portfolio id for the export request portfolio_id: int # list of scenario ids to export scenario_ids: List[int] # boolean which will overwrite the scenario ids. If this is true, we will only export the default plan for each # property and will ignore the scenario ids default_plans_only: Optional[bool] = False # Private attribute to indicate whether scenario_ids should be ignored due to default_plans_only being True _scenario_ids_ignored: bool = PrivateAttr(default=False) @model_validator(mode="after") def validate_default_plan_override(self): """ If default_plans_only is True and scenario_ids were provided, we allow execution but make it explicit that scenario_ids will be ignored. """ if self.default_plans_only and self.scenario_ids: # We do NOT raise — we allow execution. # We just mark the object so the handler can log/return a warning. object.__setattr__(self, "_scenario_ids_ignored", True) else: object.__setattr__(self, "_scenario_ids_ignored", False) return self @property def scenario_ids_ignored(self) -> bool: return self._scenario_ids_ignored