* PromptPostProcessorSelectVariableComfyUINode: optional exception and default value.

This commit is contained in:
Antonio Cordero Balcazar
2026-05-17 18:17:36 +02:00
parent 651dc240fc
commit 3766b2c9c0
2 changed files with 26 additions and 6 deletions
+25 -4
View File
@@ -63,8 +63,6 @@ class PromptPostProcessorComfyUINode:
Node for processing prompts.
"""
logger = None
def __init__(self):
lf = PromptPostProcessorLogFactory()
self.logger = lf.log
@@ -809,7 +807,8 @@ class PromptPostProcessorSelectVariableComfyUINode:
"""
def __init__(self):
pass
lf = PromptPostProcessorLogFactory()
self.logger = lf.log
@classmethod
def INPUT_TYPES(cls):
@@ -834,6 +833,23 @@ class PromptPostProcessorSelectVariableComfyUINode:
"tooltip": "Name of the variable to select",
},
),
"if_not_found": (
"COMBO",
{
"options": [e.value for e in ONWARNING_CHOICES],
"default": ONWARNING_CHOICES.warn.value,
"tooltip": "How to handle the case when the variable name is not found in the input dictionary",
},
),
"default": (
"STRING",
{
"default": "",
"multiline": False,
"dynamicPrompts": False,
"tooltip": "Default value if the variable is not found",
},
),
},
}
@@ -848,13 +864,18 @@ class PromptPostProcessorSelectVariableComfyUINode:
self,
variables: dict[str, Any],
name: str,
if_not_found: str = ONWARNING_CHOICES.warn.value,
default: str = "",
):
if variables:
if name == "":
return ("\n".join(f"{k}: {v}" for k, v in variables.items()),)
if name in variables:
return (variables[name],)
raise ValueError(f"Variable '{name}' not found in the input variables")
if if_not_found == ONWARNING_CHOICES.stop.value:
raise ValueError(f"Variable '{name}' not found in the input variables")
self.logger.warning(f"Variable '{name}' not found in the input variables")
return (default,)
raise ValueError("No variables provided to select from")
+1 -2
View File
@@ -56,13 +56,12 @@ class PromptPostProcessorLogFactory: # pylint: disable=too-few-public-methods
def __init__(self, filename=None):
"""
Initializes the PromptPostProcessor class.
Initializes the PromptPostProcessorLogFactory class.
This method sets up the logger for the PromptPostProcessor class and configures its log level and handlers.
Args:
filename (str, optional): The name of the file to log to. Defaults to None.
app (SUPPORTED_APPS): The application for which the logger is being created.
Returns:
None