Coverage for backend/ahuora-builder-types/src/ahuora_builder_types/payloads/build_state_request_schema.py: 97%
29 statements
« prev ^ index » next coverage.py v7.10.7, created at 2026-05-13 02:47 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2026-05-13 02:47 +0000
1# request types for the build_state endpoint
2from typing import Literal, Optional
3from pydantic import BaseModel
4from ahuora_builder_types.flowsheet_schema import PropertyPackageType
5from ahuora_builder_types.unit_model_schema import PropertySchema, SolvedPropertyValueSchema
8class BuildStateRequestContext(BaseModel):
9 """Django-side identifiers needed to apply an asynchronous build-state result."""
10 flowsheet_id: int
11 stream_id: int
12 task_id: int
13 property_set_id: int
14 request_version: int
17class BuildStateRequestSchema(BaseModel):
18 """build_state request schema"""
19 property_package: PropertyPackageType # property package to use
20 properties: dict[str, PropertySchema] # properties to initialize the state block with
21 context: BuildStateRequestContext
24class BuildStateResponseSchema(BaseModel):
25 """build_state response schema"""
26 properties: Optional[list[SolvedPropertyValueSchema]] # properties in the state block
27 error: Optional[str] # error message if applicable
28 log: Optional[str] # log
29 traceback: Optional[str] # traceback if applicable
32class BuildStateCompletionPayload(BaseModel):
33 """Asynchronous build-state result published by the IDAES service."""
34 context: BuildStateRequestContext
35 properties: Optional[list[SolvedPropertyValueSchema]]
36 error: Optional[str]
37 log: Optional[str]
38 traceback: Optional[str]
39 status: Literal["success", "error"]
41 @classmethod
42 def from_response(
43 cls,
44 response: BuildStateResponseSchema,
45 context: Optional[BuildStateRequestContext],
46 ) -> "BuildStateCompletionPayload":
47 """Create a completion event from the synchronous build-state response model."""
48 return cls(
49 context=context,
50 properties=response.properties,
51 error=response.error,
52 log=response.log,
53 traceback=response.traceback,
54 status="error" if response.error else "success",
55 )