From d9408f670b3abaf28a7e21592f23fd41199e2650 Mon Sep 17 00:00:00 2001 From: Sravan1011 Date: Thu, 6 Aug 2026 19:27:54 +0530 Subject: [PATCH] Fix InputParam required flag silently ignored when a non-None default is set get_block_state() substituted input_param.default before checking input_param.required, so a required input with a non-None default (easy to hit via InputParam.template("x", required=True) since the template's default carries over) never raised when omitted. Move the required check ahead of the default substitution so it always fires against the raw value passed by the caller. Fixes #14388 --- src/diffusers/modular_pipelines/modular_pipeline.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/diffusers/modular_pipelines/modular_pipeline.py b/src/diffusers/modular_pipelines/modular_pipeline.py index 9bf1ddca3b98..b9dedcbc3552 100644 --- a/src/diffusers/modular_pipelines/modular_pipeline.py +++ b/src/diffusers/modular_pipelines/modular_pipeline.py @@ -515,6 +515,8 @@ def get_block_state(self, state: PipelineState) -> dict: for input_param in state_inputs: if input_param.name: value = state.get(input_param.name) + if input_param.required and value is None: + raise ValueError(f"Required input '{input_param.name}' is missing") if value is None: # if the value is None (not passed, or passed as None), the first block that reads it sets the # default at call time. For sequential blocks the default is already resolved at compile time @@ -522,9 +524,7 @@ def get_block_state(self, state: PipelineState) -> dict: # is only known at runtime: disagreeing branch defaults merge to None (see combine_inputs) and # the block that actually runs applies its own declared default here value = input_param.default - if input_param.required and value is None: - raise ValueError(f"Required input '{input_param.name}' is missing") - elif value is not None or (value is None and input_param.name not in data): + if value is not None or (value is None and input_param.name not in data): data[input_param.name] = value elif input_param.kwargs_type: