fix(typing): resolve mypy errors in schemas.controller.computes

This commit is contained in:
Mark Paronyan 2026-09-29 22:02:22 +03:00
parent 36945daa83
commit 0954723ebd
No known key found for this signature in database
GPG Key ID: 8DC7338A87FE22F8
2 changed files with 12 additions and 9 deletions

View File

@ -38,10 +38,10 @@ class ComputeBase(BaseModel):
Data to create a compute.
"""
protocol: Protocol
host: str
port: int = Field(..., gt=0, le=65535)
user: str = None
protocol: Optional[Protocol] = None
host: Optional[str] = None
port: Optional[int] = Field(None, gt=0, le=65535)
user: Optional[str] = None
password: Optional[SecretStr] = None
name: Optional[str] = None
model_config = ConfigDict(use_enum_values=True)
@ -52,7 +52,10 @@ class ComputeCreate(ComputeBase):
Data to create a compute.
"""
compute_id: Union[str, uuid.UUID] = None
protocol: Protocol
host: str
port: int = Field(..., gt=0, le=65535)
compute_id: Optional[Union[str, uuid.UUID]] = None
model_config = ConfigDict(
json_schema_extra={
"example": {"name": "My compute", "host": "127.0.0.1", "port": 3080, "user": "user", "password": "password"}
@ -77,9 +80,6 @@ class ComputeUpdate(ComputeBase):
Data to update a compute.
"""
protocol: Optional[Protocol] = None
host: Optional[str] = None
port: Optional[int] = Field(None, gt=0, le=65535)
user: Optional[str] = None
password: Optional[SecretStr] = None
model_config = ConfigDict(
@ -110,6 +110,9 @@ class Compute(DateTimeModelMixin, ComputeBase):
Data returned for a compute.
"""
protocol: Protocol
host: str
port: int = Field(..., gt=0, le=65535)
compute_id: Union[str, uuid.UUID]
name: str
connected: Optional[bool] = Field(None, description="Whether the controller is connected to the compute or not")

View File

@ -43,7 +43,7 @@ class ComputesService:
async def create_compute(self, compute_create: schemas.ComputeCreate, connect: bool = False) -> models.Compute:
if await self._computes_repo.get_compute(compute_create.compute_id):
if compute_create.compute_id and await self._computes_repo.get_compute(compute_create.compute_id):
raise ControllerBadRequestError(f"Compute '{compute_create.compute_id}' is already registered")
db_compute = await self._computes_repo.create_compute(compute_create)
compute = await self._controller.add_compute(