Skip to content

Fix JSON serialization error in bulk import fail info API#2119

Merged
ltdrdata merged 2 commits intoComfy-Org:draft-v4from
viva-jinyi:fix/import-bulk-api-error
Sep 3, 2025
Merged

Fix JSON serialization error in bulk import fail info API#2119
ltdrdata merged 2 commits intoComfy-Org:draft-v4from
viva-jinyi:fix/import-bulk-api-error

Conversation

@viva-jinyi
Copy link
Copy Markdown
Contributor

Problem

The /v2/customnode/import_fail_info_bulk endpoint was throwing a JSON serialization error:

[ComfyUI-Manager] Error processing bulk import fail info: Object of type ImportFailInfoItem is not JSON serializable

Root Cause

The error occurred due to a mismatch between the internal data structure and the API specification:

  1. Internal data structure (cm_global.error_dict):

    {
        'name': 'node-name',
        'path': '/path/to/node',
        'msg': 'error message'
    }
  2. API spec expects (ImportFailInfoItem):

    {
        'error': 'error string',
        'traceback': 'traceback string'
    }
  3. The code was trying to serialize the Pydantic model ImportFailInfoBulkResponse which contained incompatible data structures, causing the serialization failure.

Solution

  • Transform the data from cm_global.error_dict format to match the API specification
  • Map msg field to error field
  • Add empty traceback field when not present
  • Remove Pydantic model serialization and return plain dict directly as JSON

Changes Made

  1. Added data transformation in the bulk endpoint to convert error dict format:

    results[cnr_id] = {
        'error': info.get('msg', ''),
        'traceback': info.get('traceback', '')
    }
  2. Removed problematic Pydantic model serialization:

    • Before: return web.json_response(response_data.root)
    • After: return web.json_response(results, content_type="application/json")

Testing

Tested with the following curl command and confirmed it returns proper JSON response without errors:

curl 'http://localhost:8188/api/v2/customnode/import_fail_info_bulk' \
  -H 'Content-Type: application/json' \
  --data-raw '{"cnr_ids":["comfyui-manager","teacache","comfyui-gguf"]}'

Impact

  • Fixes the 500 Internal Server Error when calling the bulk import fail info endpoint
  • Ensures consistent API response format across single and bulk endpoints
  • Maintains backward compatibility with existing API contracts

@ltdrdata ltdrdata merged commit e13bf68 into Comfy-Org:draft-v4 Sep 3, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants