@@ -186,6 +186,39 @@ def __init__(self, *args, **kwargs):
186186 super ().__init__ (* args , ** kwargs )
187187 self .fields ['scene' ].required = False
188188
189+ # Added validation to ensure all models in camerachain exist in model_config
190+ def clean_camerachain (self ):
191+ camerachain = self .cleaned_data .get ('camerachain' , '' ).strip ()
192+ if not camerachain :
193+ return camerachain
194+
195+ from pathlib import Path
196+ from manager .ppl_generator .model_chain import CameraChainOperations
197+
198+ # Load model config
199+ model_config_path = Path (os .environ .get ('MODEL_CONFIGS_FOLDER' , '/models/model_configs' )) / 'model_config.json'
200+ if not model_config_path .is_file ():
201+ raise ValidationError (f"Model config file not found at { model_config_path } " )
202+
203+ try :
204+ with open (model_config_path , 'r' ) as f :
205+ model_config = json .load (f )
206+ except (json .JSONDecodeError , IOError ) as e :
207+ raise ValidationError (f"Error reading model config: { str (e )} " )
208+
209+ # Extract model names from chain
210+ chain_parts = camerachain .replace (CameraChainOperations .PARALLEL .value , CameraChainOperations .SEQUENTIAL .value )
211+ model_names = [part .split ('=' )[0 ].strip () for part in chain_parts .split (CameraChainOperations .SEQUENTIAL .value ) if part .strip ()]
212+
213+ # Validate models exist
214+ missing = [m for m in model_names if m not in model_config ]
215+ if missing :
216+ missing_str = ', ' .join (f"'{ m } '" for m in missing )
217+ available = ', ' .join (f"'{ m } '" for m in sorted (model_config .keys ()))
218+ raise ValidationError (f"Error adding camera: Model(s) { missing_str } not found in model config file. Available models: { available } " )
219+
220+ return camerachain
221+
189222class ChildSceneForm (forms .ModelForm ):
190223 class Meta :
191224 model = ChildScene
0 commit comments