[backport core/1.33] Fix workflow loading from PNG images with both workflow and parameter… (#7265)

Backport of #7154 to `core/1.33`

Automatically created by backport workflow.

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-7265-backport-core-1-33-Fix-workflow-loading-from-PNG-images-with-both-workflow-and-paramete-2c46d73d365081e2b6f2dcbec3f2ba04)
by [Unito](https://www.unito.io)

---------

Co-authored-by: Rvage <skentler@protonmail.com>
Co-authored-by: Alexander Brown <DrJKL0424@gmail.com>
Co-authored-by: Alexander Brown <drjkl@comfy.org>
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Comfy Org PR Bot
2025-12-09 11:21:44 +09:00
committed by GitHub
parent 386e10516e
commit cb6d33007c

View File

@@ -1057,7 +1057,13 @@ export class ComfyApp {
}
let reset_invalid_values = false
if (!graphData) {
// Use explicit validation instead of falsy check to avoid replacing
// valid but falsy values (empty objects, 0, false, etc.)
if (
!graphData ||
typeof graphData !== 'object' ||
Array.isArray(graphData)
) {
graphData = defaultGraph
reset_invalid_values = true
}
@@ -1432,6 +1438,38 @@ export class ComfyApp {
this.loadTemplateData({ templates })
}
// Check workflow first - it should take priority over parameters
// when both are present (e.g., in ComfyUI-generated PNGs)
if (workflow) {
let workflowObj: ComfyWorkflowJSON | undefined = undefined
try {
workflowObj =
typeof workflow === 'string' ? JSON.parse(workflow) : workflow
// Only load workflow if parsing succeeded AND validation passed
if (
workflowObj &&
typeof workflowObj === 'object' &&
!Array.isArray(workflowObj)
) {
await this.loadGraphData(workflowObj, true, true, fileName, {
openSource
})
return
} else {
console.error(
'Invalid workflow structure, trying parameters fallback'
)
this.showErrorOnFileLoad(file)
}
} catch (err) {
console.error('Failed to parse workflow:', err)
this.showErrorOnFileLoad(file)
// Fall through to check parameters as fallback
}
}
// Use parameters as fallback when no workflow exists
if (parameters) {
// Note: Not putting this in `importA1111` as it is mostly not used
// by external callers, and `importA1111` has no access to `app`.
@@ -1444,15 +1482,6 @@ export class ComfyApp {
return
}
if (workflow) {
const workflowObj =
typeof workflow === 'string' ? JSON.parse(workflow) : workflow
await this.loadGraphData(workflowObj, true, true, fileName, {
openSource
})
return
}
if (prompt) {
const promptObj = typeof prompt === 'string' ? JSON.parse(prompt) : prompt
this.loadApiJson(promptObj, fileName)