Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(webv2): accept empty strings as workflow string values

Josh Corbett4ecfc06982a6
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.test.ts b/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.test.ts
index c6a7599b7d..a5c95769ca 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.test.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.test.ts
@@ -150,14 +150,23 @@ describe('getProjectGraphReadiness', () => {
it('reports missing required inputs and unknown node types', () => {
const { doc, sourceId } = buildDocument();
- const withEmptyValue = projectGraphReducer(doc, {
+ const withEmptyString = projectGraphReducer(doc, {
fieldName: 'value',
nodeId: sourceId,
type: 'setFieldValue',
value: '',
});
- expect(getProjectGraphReadiness(withEmptyValue, loadedSnapshot).reasons[0]).toMatch(/missing required input/);
+ expect(getProjectGraphReadiness(withEmptyString, loadedSnapshot)).toEqual({ canInvoke: true, reasons: [] });
+
+ const withMissingValue = projectGraphReducer(doc, {
+ fieldName: 'value',
+ nodeId: sourceId,
+ type: 'setFieldValue',
+ value: undefined,
+ });
+
+ expect(getProjectGraphReadiness(withMissingValue, loadedSnapshot).reasons[0]).toMatch(/missing required input/);
const unknownTemplates: InvocationTemplatesSnapshot = {
error: null,
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.ts b/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.ts
index 680ab92200..f0947d800a 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.ts
@@ -47,8 +47,10 @@ export const isExecutableInvocationType = (type: string): boolean => !UNSUPPORTE
const getExecutableNodes = (document: ProjectGraphState): WorkflowInvocationNode[] =>
document.nodes.filter(isInvocationNode);
+const isMissingValue = (value: unknown): boolean => value === undefined || value === null;
+
const isEmptyValue = (value: unknown): boolean =>
- value === undefined || value === null || (typeof value === 'string' && value.trim() === '');
+ isMissingValue(value) || (typeof value === 'string' && value.trim() === '');
const getNodeDisplayName = (node: WorkflowInvocationNode, templates: InvocationTemplates): string =>
node.data.label || templates[node.data.type]?.title || node.data.type;
@@ -136,7 +138,7 @@ export const getProjectGraphReadiness = (
value: node.data.inputs[inputTemplate.name]?.value,
});
- if (inputTemplate.required && isEmptyValue(node.data.inputs[inputTemplate.name]?.value)) {
+ if (inputTemplate.required && isMissingValue(node.data.inputs[inputTemplate.name]?.value)) {
reasons.push(`"${getNodeDisplayName(node, templates)}" is missing required input "${inputTemplate.title}".`);
} else if (invalidReason) {
reasons.push(`"${getNodeDisplayName(node, templates)}" has invalid input "${inputTemplate.title}".`);
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/fields.test.ts b/invokeai/frontend/webv2/src/features/workflow/core/fields.test.ts
index 7bd1af979d..5db37d6aad 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/fields.test.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/fields.test.ts
@@ -44,8 +44,10 @@ const input = (overrides: Partial<FieldInputTemplate> = {}): FieldInputTemplate
});
describe('workflow field validation', () => {
- it('flags empty required direct values and ignores optional fields', () => {
- expect(getWorkflowFieldInvalidReason({ isConnected: false, template: input(), value: '' })).toBe('Required value.');
+ it('flags missing required direct values and ignores optional fields', () => {
+ expect(getWorkflowFieldInvalidReason({ isConnected: false, template: input(), value: undefined })).toBe(
+ 'Required value.'
+ );
expect(getWorkflowFieldInvalidReason({ isConnected: false, template: input({ required: false }), value: '' })).toBe(
null
);
@@ -53,6 +55,12 @@ describe('workflow field validation', () => {
it('treats connected required fields as valid', () => {
expect(
+ it('accepts an empty string as a required string value', () => {
+ expect(getWorkflowFieldInvalidReason({ isConnected: false, template: input(), value: '' })).toBe(null);
+ expect(isWorkflowFieldValueValid(input(), '')).toBe(true);
+ expect(isWorkflowFieldValueValid(input({ options: ['a'], type: single('EnumField') }), '')).toBe(false);
+ });
+
getWorkflowFieldInvalidReason({ isConnected: true, template: input({ input: 'connection' }), value: '' })
).toBe(null);
});
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/fields.ts b/invokeai/frontend/webv2/src/features/workflow/core/fields.ts
index 53749159d4..2bf653f0ed 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/fields.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/fields.ts
@@ -179,7 +179,8 @@ export const isWorkflowFieldValueValid = (template: FieldInputTemplate, value: u
// models through untouched.
return Array.isArray(value) ? value.every(isLoraFieldCollectionEntry) : isLoraFieldCollectionEntry(value);
case 'SchedulerField':
- return isNonEmptyString(value);
+ // An empty string is a legitimate string value (e.g. a blank negative prompt).
+ return typeof value === 'string';
case 'BoardField':
return (
value === undefined ||