mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-03-22 17:43:33 +08:00
Require at least one tag in UploadAssetSpec
Enforce non-empty tags at the Pydantic validation layer so uploads with no tags are rejected with a 400 before reaching ingest. Adds test_upload_empty_tags_rejected to cover this case. Amp-Thread-ID: https://ampcode.com/threads/T-019ce377-8bde-7048-bc28-a9df063409f9 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
parent
aa953a2fdc
commit
9cfb9c7a9d
@ -333,13 +333,14 @@ class UploadAssetSpec(BaseModel):
|
|||||||
|
|
||||||
@model_validator(mode="after")
|
@model_validator(mode="after")
|
||||||
def _validate_order(self):
|
def _validate_order(self):
|
||||||
if self.tags:
|
if not self.tags:
|
||||||
root = self.tags[0]
|
raise ValueError("at least one tag is required for uploads")
|
||||||
if root not in {"models", "input", "output"}:
|
root = self.tags[0]
|
||||||
raise ValueError("first tag must be one of: models, input, output")
|
if root not in {"models", "input", "output"}:
|
||||||
if root == "models":
|
raise ValueError("first tag must be one of: models, input, output")
|
||||||
if len(self.tags) < 2:
|
if root == "models":
|
||||||
raise ValueError(
|
if len(self.tags) < 2:
|
||||||
"models uploads require a category tag as the second tag"
|
raise ValueError(
|
||||||
)
|
"models uploads require a category tag as the second tag"
|
||||||
|
)
|
||||||
return self
|
return self
|
||||||
|
|||||||
@ -243,6 +243,15 @@ def test_upload_tags_traversal_guard(http: requests.Session, api_base: str):
|
|||||||
assert body["error"]["code"] in ("BAD_REQUEST", "INVALID_BODY")
|
assert body["error"]["code"] in ("BAD_REQUEST", "INVALID_BODY")
|
||||||
|
|
||||||
|
|
||||||
|
def test_upload_empty_tags_rejected(http: requests.Session, api_base: str):
|
||||||
|
files = {"file": ("notags.bin", b"A" * 64, "application/octet-stream")}
|
||||||
|
form = {"tags": json.dumps([]), "name": "notags.bin", "user_metadata": json.dumps({})}
|
||||||
|
r = http.post(api_base + "/api/assets", data=form, files=files, timeout=120)
|
||||||
|
body = r.json()
|
||||||
|
assert r.status_code == 400
|
||||||
|
assert body["error"]["code"] == "INVALID_BODY"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("root", ["input", "output"])
|
@pytest.mark.parametrize("root", ["input", "output"])
|
||||||
def test_duplicate_upload_same_display_name_does_not_clobber(
|
def test_duplicate_upload_same_display_name_does_not_clobber(
|
||||||
root: str,
|
root: str,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user