From e3942dbcecf1bd84e1aa74a388e52772259af15e Mon Sep 17 00:00:00 2001 From: dev-willbird1936 Date: Sat, 25 Jul 2026 13:32:47 +0100 Subject: [PATCH] fix(server): return 400 for unknown /upload/image type instead of 500 get_dir_by_type() only bound type_dir for dir_type in {None, "input", "temp", "output"}. Any other value fell through to `return type_dir, dir_type` with type_dir never assigned, raising UnboundLocalError, which aiohttp surfaced as an unhandled HTTP 500. POST /upload/image and POST /upload/mask both take the type value straight from the multipart body, so a client typo such as type=foo produced a server error where a client error is correct. Return None for an unrecognised type and have image_upload answer 400. Recognised values are unchanged. --- server.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server.py b/server.py index e28fe2d22..61e6fc3f5 100644 --- a/server.py +++ b/server.py @@ -377,6 +377,10 @@ class PromptServer(): type_dir = folder_paths.get_temp_directory() elif dir_type == "output": type_dir = folder_paths.get_output_directory() + else: + # Unrecognised type: signal "no directory" instead of falling + # through to an unbound `type_dir` (UnboundLocalError -> 500). + return None, dir_type return type_dir, dir_type @@ -401,6 +405,8 @@ class PromptServer(): image_upload_type = post.get("type") upload_dir, image_upload_type = get_dir_by_type(image_upload_type) + if upload_dir is None: + return web.Response(status=400) if image and image.file: filename = image.filename