mirror of
https://github.com/Comfy-Org/ComfyUI-Manager.git
synced 2025-12-16 18:02:58 +08:00
feat: Add Pydantic validation to import_fail_info_bulk endpoint
- Regenerated Pydantic models from updated OpenAPI specification - Updated import_fail_info_bulk route handler to use ImportFailInfoBulkRequest/Response models - Replaced manual JSON validation with Pydantic model validation - Added proper error handling with ValidationError - Updated data_models/__init__.py to export new models Following the process outlined in data_models/README.md for type safety and consistency.
This commit is contained in:
parent
9c4d6a0773
commit
300c6e7406
@ -30,6 +30,12 @@ from .generated_models import (
|
|||||||
InstalledModelInfo,
|
InstalledModelInfo,
|
||||||
ComfyUIVersionInfo,
|
ComfyUIVersionInfo,
|
||||||
|
|
||||||
|
# Import Fail Info Models
|
||||||
|
ImportFailInfoBulkRequest,
|
||||||
|
ImportFailInfoBulkResponse,
|
||||||
|
ImportFailInfoItem,
|
||||||
|
ImportFailInfoItem1,
|
||||||
|
|
||||||
# Other models
|
# Other models
|
||||||
OperationType,
|
OperationType,
|
||||||
OperationResult,
|
OperationResult,
|
||||||
@ -88,6 +94,12 @@ __all__ = [
|
|||||||
"InstalledModelInfo",
|
"InstalledModelInfo",
|
||||||
"ComfyUIVersionInfo",
|
"ComfyUIVersionInfo",
|
||||||
|
|
||||||
|
# Import Fail Info Models
|
||||||
|
"ImportFailInfoBulkRequest",
|
||||||
|
"ImportFailInfoBulkResponse",
|
||||||
|
"ImportFailInfoItem",
|
||||||
|
"ImportFailInfoItem1",
|
||||||
|
|
||||||
# Other models
|
# Other models
|
||||||
"OperationType",
|
"OperationType",
|
||||||
"OperationResult",
|
"OperationResult",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
# generated by datamodel-codegen:
|
# generated by datamodel-codegen:
|
||||||
# filename: openapi.yaml
|
# filename: openapi.yaml
|
||||||
# timestamp: 2025-06-27T04:01:45+00:00
|
# timestamp: 2025-07-31T04:52:26+00:00
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
@ -454,6 +454,24 @@ class BatchExecutionRecord(BaseModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ImportFailInfoBulkRequest(BaseModel):
|
||||||
|
cnr_ids: Optional[List[str]] = Field(
|
||||||
|
None, description="A list of CNR IDs to check."
|
||||||
|
)
|
||||||
|
urls: Optional[List[str]] = Field(
|
||||||
|
None, description="A list of repository URLs to check."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ImportFailInfoItem1(BaseModel):
|
||||||
|
error: Optional[str] = None
|
||||||
|
traceback: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
class ImportFailInfoItem(RootModel[Optional[ImportFailInfoItem1]]):
|
||||||
|
root: Optional[ImportFailInfoItem1]
|
||||||
|
|
||||||
|
|
||||||
class QueueTaskItem(BaseModel):
|
class QueueTaskItem(BaseModel):
|
||||||
ui_id: str = Field(..., description="Unique identifier for the task")
|
ui_id: str = Field(..., description="Unique identifier for the task")
|
||||||
client_id: str = Field(..., description="Client identifier that initiated the task")
|
client_id: str = Field(..., description="Client identifier that initiated the task")
|
||||||
@ -537,3 +555,7 @@ class HistoryResponse(BaseModel):
|
|||||||
history: Optional[Dict[str, TaskHistoryItem]] = Field(
|
history: Optional[Dict[str, TaskHistoryItem]] = Field(
|
||||||
None, description="Map of task IDs to their history items"
|
None, description="Map of task IDs to their history items"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ImportFailInfoBulkResponse(RootModel[Optional[Dict[str, ImportFailInfoItem]]]):
|
||||||
|
root: Optional[Dict[str, ImportFailInfoItem]] = None
|
||||||
|
|||||||
@ -61,6 +61,8 @@ from ..data_models import (
|
|||||||
ManagerMessageName,
|
ManagerMessageName,
|
||||||
BatchExecutionRecord,
|
BatchExecutionRecord,
|
||||||
ComfyUISystemState,
|
ComfyUISystemState,
|
||||||
|
ImportFailInfoBulkRequest,
|
||||||
|
ImportFailInfoBulkResponse,
|
||||||
BatchOperation,
|
BatchOperation,
|
||||||
InstalledNodeInfo,
|
InstalledNodeInfo,
|
||||||
ComfyUIVersionInfo,
|
ComfyUIVersionInfo,
|
||||||
@ -1660,12 +1662,12 @@ async def import_fail_info(request):
|
|||||||
async def import_fail_info_bulk(request):
|
async def import_fail_info_bulk(request):
|
||||||
try:
|
try:
|
||||||
json_data = await request.json()
|
json_data = await request.json()
|
||||||
|
|
||||||
# Basic validation - ensure we have either cnr_ids or urls
|
# Validate input using Pydantic model
|
||||||
if not isinstance(json_data, dict):
|
request_data = ImportFailInfoBulkRequest.model_validate(json_data)
|
||||||
return web.Response(status=400, text="Request body must be a JSON object")
|
|
||||||
|
# Ensure we have either cnr_ids or urls
|
||||||
if "cnr_ids" not in json_data and "urls" not in json_data:
|
if not request_data.cnr_ids and not request_data.urls:
|
||||||
return web.Response(
|
return web.Response(
|
||||||
status=400, text="Either 'cnr_ids' or 'urls' field is required"
|
status=400, text="Either 'cnr_ids' or 'urls' field is required"
|
||||||
)
|
)
|
||||||
@ -1675,13 +1677,8 @@ async def import_fail_info_bulk(request):
|
|||||||
|
|
||||||
results = {}
|
results = {}
|
||||||
|
|
||||||
if "cnr_ids" in json_data:
|
if request_data.cnr_ids:
|
||||||
if not isinstance(json_data["cnr_ids"], list):
|
for cnr_id in request_data.cnr_ids:
|
||||||
return web.Response(status=400, text="'cnr_ids' must be an array")
|
|
||||||
for cnr_id in json_data["cnr_ids"]:
|
|
||||||
if not isinstance(cnr_id, str):
|
|
||||||
results[cnr_id] = {"error": "cnr_id must be a string"}
|
|
||||||
continue
|
|
||||||
module_name = core.unified_manager.get_module_name(cnr_id)
|
module_name = core.unified_manager.get_module_name(cnr_id)
|
||||||
if module_name is not None:
|
if module_name is not None:
|
||||||
info = cm_global.error_dict.get(module_name)
|
info = cm_global.error_dict.get(module_name)
|
||||||
@ -1692,13 +1689,8 @@ async def import_fail_info_bulk(request):
|
|||||||
else:
|
else:
|
||||||
results[cnr_id] = None
|
results[cnr_id] = None
|
||||||
|
|
||||||
if "urls" in json_data:
|
if request_data.urls:
|
||||||
if not isinstance(json_data["urls"], list):
|
for url in request_data.urls:
|
||||||
return web.Response(status=400, text="'urls' must be an array")
|
|
||||||
for url in json_data["urls"]:
|
|
||||||
if not isinstance(url, str):
|
|
||||||
results[url] = {"error": "url must be a string"}
|
|
||||||
continue
|
|
||||||
module_name = core.unified_manager.get_module_name(url)
|
module_name = core.unified_manager.get_module_name(url)
|
||||||
if module_name is not None:
|
if module_name is not None:
|
||||||
info = cm_global.error_dict.get(module_name)
|
info = cm_global.error_dict.get(module_name)
|
||||||
@ -1709,7 +1701,12 @@ async def import_fail_info_bulk(request):
|
|||||||
else:
|
else:
|
||||||
results[url] = None
|
results[url] = None
|
||||||
|
|
||||||
return web.json_response(results)
|
# Create response using Pydantic model
|
||||||
|
response_data = ImportFailInfoBulkResponse(root=results)
|
||||||
|
return web.json_response(response_data.root)
|
||||||
|
except ValidationError as e:
|
||||||
|
logging.error(f"[ComfyUI-Manager] Invalid request data: {e}")
|
||||||
|
return web.Response(status=400, text=f"Invalid request data: {e}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"[ComfyUI-Manager] Error processing bulk import fail info: {e}")
|
logging.error(f"[ComfyUI-Manager] Error processing bulk import fail info: {e}")
|
||||||
return web.Response(status=500, text="Internal server error")
|
return web.Response(status=500, text="Internal server error")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user