1515from models_library .services_regex import SERVICE_KEY_RE
1616from models_library .services_resources import BootMode
1717from pydantic import (
18- TypeAdapter , ValidationInfo , field_validator , ConfigDict , BaseModel ,
18+ BaseModel ,
1919 ByteSize ,
20+ ConfigDict ,
2021 Field ,
2122 PositiveInt ,
23+ TypeAdapter ,
24+ ValidationInfo ,
25+ field_validator ,
2226)
2327from simcore_postgres_database .models .comp_pipeline import StateType
2428from simcore_postgres_database .models .comp_tasks import NodeClass
@@ -37,7 +41,9 @@ class Image(BaseModel):
3741 default = None , deprecated = True , description = "Use instead node_requirements"
3842 )
3943 node_requirements : NodeRequirements | None = Field (
40- default = None , description = "the requirements for the service to run on a node" , validate_default = True
44+ default = None ,
45+ description = "the requirements for the service to run on a node" ,
46+ validate_default = True ,
4147 )
4248 boot_mode : BootMode = BootMode .CPU
4349 command : list [str ] = Field (
@@ -64,6 +70,7 @@ def migrate_from_requirements(cls, v, info: ValidationInfo):
6470 RAM = TypeAdapter (ByteSize ).validate_python ("128 MiB" ),
6571 )
6672 return v
73+
6774 model_config = ConfigDict (
6875 from_attributes = True ,
6976 json_schema_extra = {
@@ -73,7 +80,9 @@ def migrate_from_requirements(cls, v, info: ValidationInfo):
7380 "tag" : "1.3.1" ,
7481 "node_requirements" : node_req_example ,
7582 }
76- for node_req_example in NodeRequirements .model_config ["json_schema_extra" ]["examples" ]
83+ for node_req_example in NodeRequirements .model_config [
84+ "json_schema_extra"
85+ ]["examples" ]
7786 ]
7887 +
7988 # old version
@@ -85,16 +94,14 @@ def migrate_from_requirements(cls, v, info: ValidationInfo):
8594 "requires_mpi" : False ,
8695 }
8796 ]
88- }
97+ },
8998 )
9099
91100
92101# NOTE: for a long time defaultValue field was added to ServiceOutput wrongly in the DB.
93102# this flags allows parsing of the outputs without error. This MUST not leave the director-v2!
94103class _ServiceOutputOverride (ServiceOutput ):
95- model_config = ConfigDict (
96- extra = "ignore"
97- )
104+ model_config = ConfigDict (extra = "ignore" )
98105
99106
100107_ServiceOutputsOverride = dict [ServicePortKey , _ServiceOutputOverride ]
@@ -103,7 +110,7 @@ class _ServiceOutputOverride(ServiceOutput):
103110class NodeSchema (BaseModel ):
104111 inputs : ServiceInputsDict = Field (..., description = "the inputs scheam" )
105112 outputs : _ServiceOutputsOverride = Field (..., description = "the outputs schema" )
106- model_config = ConfigDict (extra = "ignore" , extra = " forbid" , from_attributes = True )
113+ model_config = ConfigDict (extra = "forbid" , from_attributes = True )
107114
108115
109116class CompTaskAtDB (BaseModel ):
@@ -170,8 +177,73 @@ def backward_compatible_null_value(cls, v: HardwareInfo | None) -> HardwareInfo:
170177 return v
171178
172179 def to_db_model (self , ** exclusion_rules ) -> dict [str , Any ]:
173- comp_task_dict = self .model_dump (by_alias = True , exclude_unset = True , ** exclusion_rules )
180+ comp_task_dict = self .model_dump (
181+ by_alias = True , exclude_unset = True , ** exclusion_rules
182+ )
174183 if "state" in comp_task_dict :
175184 comp_task_dict ["state" ] = RUNNING_STATE_TO_DB [comp_task_dict ["state" ]].value
176185 return comp_task_dict
177- model_config = ConfigDict (extra = "forbid" , from_attributes = True )
186+
187+ model_config = ConfigDict (
188+ extra = "forbid" ,
189+ from_attributes = True ,
190+ json_schema_extra = {
191+ "examples" : [
192+ # DB model
193+ {
194+ "task_id" : 324 ,
195+ "project_id" : "341351c4-23d1-4366-95d0-bc01386001a7" ,
196+ "node_id" : "7f62be0e-1298-4fe4-be76-66b6e859c260" ,
197+ "job_id" : None ,
198+ "internal_id" : 3 ,
199+ "schema" : {
200+ "inputs" : {
201+ "input_1" : {
202+ "label" : "input_files" ,
203+ "description" : "Any input files. One or serveral files compressed in a zip will be downloaded in an inputs folder." ,
204+ "type" : "data:*/*" ,
205+ "displayOrder" : 1.0 ,
206+ }
207+ },
208+ "outputs" : {
209+ "output_1" : {
210+ "label" : "Output files" ,
211+ "description" : "Output files uploaded from the outputs folder" ,
212+ "type" : "data:*/*" ,
213+ "displayOrder" : 1.0 ,
214+ }
215+ },
216+ },
217+ "inputs" : {
218+ "input_1" : {
219+ "nodeUuid" : "48a7ac7a-cfc3-44a6-ba9b-5a1a578b922c" ,
220+ "output" : "output_1" ,
221+ }
222+ },
223+ "outputs" : {
224+ "output_1" : {
225+ "store" : 0 ,
226+ "path" : "341351c4-23d1-4366-95d0-bc01386001a7/7f62be0e-1298-4fe4-be76-66b6e859c260/output_1.zip" ,
227+ }
228+ },
229+ "image" : image_example ,
230+ "submit" : "2021-03-01 13:07:34.19161" ,
231+ "node_class" : "INTERACTIVE" ,
232+ "state" : "NOT_STARTED" ,
233+ "progress" : 0.44 ,
234+ "last_heartbeat" : None ,
235+ "created" : "2022-05-20 13:28:31.139+00" ,
236+ "modified" : "2023-06-23 15:58:32.833081+00" ,
237+ "pricing_info" : {
238+ "pricing_plan_id" : 1 ,
239+ "pricing_unit_id" : 1 ,
240+ "pricing_unit_cost_id" : 1 ,
241+ },
242+ "hardware_info" : HardwareInfo .model_config ["json_schema_extra" ][
243+ "examples"
244+ ][0 ],
245+ }
246+ for image_example in Image .model_config ["json_schema_extra" ]["examples" ]
247+ ]
248+ },
249+ )
0 commit comments