Handle missing internal nodes

This commit is contained in:
pythongosssss 2023-11-04 11:44:01 +00:00
parent b3f759d979
commit f9ff5d9105
3 changed files with 59 additions and 7 deletions

View File

@ -541,4 +541,43 @@ describe("group node", () => {
}) })
); );
}); });
test("shows missing node error on missing internal node when loading graph data", async () => {
const { graph } = await start();
const dialogShow = jest.spyOn(graph.app.ui.dialog, "show");
await graph.app.loadGraphData({
last_node_id: 3,
last_link_id: 1,
nodes: [
{
id: 3,
type: "workflow/testerror",
},
],
links: [],
groups: [],
config: {},
extra: {
groupNodes: {
testerror: {
nodes: [
{
type: "NotKSampler",
},
{
type: "NotVAEDecode",
},
],
},
},
},
});
expect(dialogShow).toBeCalledTimes(1);
const call = dialogShow.mock.calls[0][0];
expect(call).toContain("the following node types were not found");
expect(call).toContain("NotKSampler");
expect(call).toContain("NotVAEDecode");
expect(call).toContain("workflow/testerror");
});
}); });

View File

@ -6,7 +6,7 @@ export const IS_GROUP_NODE = Symbol();
export const GROUP_DATA = Symbol(); export const GROUP_DATA = Symbol();
const GROUP_SLOTS = Symbol(); const GROUP_SLOTS = Symbol();
export async function registerGroupNodes(groupNodes, source, prefix) { export async function registerGroupNodes(groupNodes, source, prefix, missingNodeTypes) {
if (!groupNodes) return; if (!groupNodes) return;
let extra = app.graph.extra; let extra = app.graph.extra;
@ -15,7 +15,20 @@ export async function registerGroupNodes(groupNodes, source, prefix) {
if (!nodes) extra.groupNodes = nodes = {}; if (!nodes) extra.groupNodes = nodes = {};
for (const g in groupNodes) { for (const g in groupNodes) {
const def = buildNodeDef(groupNodes[g], g, globalDefs, source); const groupData = groupNodes[g];
let hasMissing = false;
for (const n of groupData.nodes) {
// Find missing node types
if (!(n.type in LiteGraph.registered_node_types)) {
missingNodeTypes.push(n.type);
hasMissing = true;
}
}
if (hasMissing) continue;
const def = buildNodeDef(groupData, g, globalDefs, source);
if (prefix) { if (prefix) {
def.display_name = prefix + "/" + def.display_name; def.display_name = prefix + "/" + def.display_name;
} }
@ -319,7 +332,7 @@ class ConvertToGroupAction {
Object.values(app.canvas.selected_nodes).find((n) => n.constructor.nodeData?.[IS_GROUP_NODE]), Object.values(app.canvas.selected_nodes).find((n) => n.constructor.nodeData?.[IS_GROUP_NODE]),
callback: async () => { callback: async () => {
const name = this.getName(); const name = this.getName();
if(!name) return; if (!name) return;
let extra = app.graph.extra; let extra = app.graph.extra;
if (!extra) app.graph.extra = extra = {}; if (!extra) app.graph.extra = extra = {};
@ -402,8 +415,8 @@ const ext = {
}; };
} }
}, },
async beforeConfigureGraph(graphData) { async beforeConfigureGraph(graphData, missingNodeTypes) {
registerGroupNodes(graphData?.extra?.groupNodes, "workflow"); registerGroupNodes(graphData?.extra?.groupNodes, "workflow", undefined, missingNodeTypes);
}, },
addCustomNodeDefs(defs) { addCustomNodeDefs(defs) {
globalDefs = defs; globalDefs = defs;

View File

@ -1486,8 +1486,8 @@ export class ComfyApp {
reset_invalid_values = true; reset_invalid_values = true;
} }
await this.#invokeExtensionsAsync("beforeConfigureGraph", graphData);
const missingNodeTypes = []; const missingNodeTypes = [];
await this.#invokeExtensionsAsync("beforeConfigureGraph", graphData, missingNodeTypes);
for (let n of graphData.nodes) { for (let n of graphData.nodes) {
// Patch T2IAdapterLoader to ControlNetLoader since they are the same node now // Patch T2IAdapterLoader to ControlNetLoader since they are the same node now
if (n.type == "T2IAdapterLoader") n.type = "ControlNetLoader"; if (n.type == "T2IAdapterLoader") n.type = "ControlNetLoader";