Skip to content

Commit 15880e6

Browse files
fix(ui): invocation parsing for optional enum fields
For example: ```py my_field: Literal["foo", "bar"] | None = InputField(default=None) ``` Previously, this would cause a field parsing error and prevent the app from loading. Two fixes: - This type annotation and resultant schema are now parsed correctly - Error handling added to template building logic to prevent the hang at startup when an error does occur
1 parent 53ffa98 commit 15880e6

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

invokeai/frontend/web/src/features/nodes/util/schema/buildFieldInputTemplate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ const buildEnumFieldInputTemplate: FieldInputTemplateBuilder<EnumFieldInputTempl
682682
if (filteredAnyOf.length !== 1 || !isSchemaObject(firstAnyOf)) {
683683
options = [];
684684
} else {
685-
options = firstAnyOf.enum ?? [];
685+
options = firstAnyOf.const ? [firstAnyOf.const] : (firstAnyOf.enum ?? []);
686686
}
687687
} else if (schemaObject.const) {
688688
options = [schemaObject.const];

invokeai/frontend/web/src/features/nodes/util/schema/parseSchema.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,15 @@ export const parseSchema = (
161161
fieldType.batch = true;
162162
}
163163

164-
const fieldInputTemplate = buildFieldInputTemplate(property, propertyName, fieldType);
165-
inputsAccumulator[propertyName] = fieldInputTemplate;
164+
try {
165+
const fieldInputTemplate = buildFieldInputTemplate(property, propertyName, fieldType);
166+
inputsAccumulator[propertyName] = fieldInputTemplate;
167+
} catch {
168+
log.error(
169+
{ node: type, field: propertyName, schema: parseify(property) },
170+
'Problem building input field template'
171+
);
172+
}
166173

167174
return inputsAccumulator;
168175
},
@@ -226,9 +233,16 @@ export const parseSchema = (
226233
fieldType.batch = true;
227234
}
228235

229-
const fieldOutputTemplate = buildFieldOutputTemplate(property, propertyName, fieldType);
236+
try {
237+
const fieldOutputTemplate = buildFieldOutputTemplate(property, propertyName, fieldType);
238+
outputsAccumulator[propertyName] = fieldOutputTemplate;
239+
} catch {
240+
log.error(
241+
{ node: type, field: propertyName, schema: parseify(property) },
242+
'Problem building output field template'
243+
);
244+
}
230245

231-
outputsAccumulator[propertyName] = fieldOutputTemplate;
232246
return outputsAccumulator;
233247
},
234248
{} as Record<string, FieldOutputTemplate>

0 commit comments

Comments
 (0)