fix(tags): invalid 'copyright' kind 500 — KINDS uses real enum 'fandom'; directory 400s on bad kind
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -56,6 +56,8 @@ async def autocomplete():
|
|||||||
@tags_bp.route("/tags/directory", methods=["GET"])
|
@tags_bp.route("/tags/directory", methods=["GET"])
|
||||||
async def directory():
|
async def directory():
|
||||||
kind = request.args.get("kind") or None
|
kind = request.args.get("kind") or None
|
||||||
|
if kind is not None and _coerce_kind(kind) is None:
|
||||||
|
return jsonify({"error": f"invalid kind {kind!r}"}), 400
|
||||||
q = request.args.get("q") or None
|
q = request.args.get("q") or None
|
||||||
cursor = request.args.get("cursor") or None
|
cursor = request.args.get("cursor") or None
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -51,7 +51,10 @@ import { useTagDirectoryStore } from '../stores/tagDirectory.js'
|
|||||||
import TagCard from '../components/discovery/TagCard.vue'
|
import TagCard from '../components/discovery/TagCard.vue'
|
||||||
import MergeConfirmDialog from '../components/discovery/MergeConfirmDialog.vue'
|
import MergeConfirmDialog from '../components/discovery/MergeConfirmDialog.vue'
|
||||||
|
|
||||||
const KINDS = ['artist', 'character', 'copyright', 'general', 'series', 'meta']
|
// Must stay a subset of the backend TagKind enum (artist, character,
|
||||||
|
// fandom, general, series, archive, post, meta, rating). 'fandom' is this
|
||||||
|
// model's copyright/franchise concept (characters link via fandom_id).
|
||||||
|
const KINDS = ['artist', 'character', 'fandom', 'general', 'series', 'meta']
|
||||||
const store = useTagDirectoryStore()
|
const store = useTagDirectoryStore()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
|
|||||||
@@ -28,3 +28,22 @@ async def test_directory_endpoint(client, db):
|
|||||||
async def test_directory_bad_limit(client):
|
async def test_directory_bad_limit(client):
|
||||||
resp = await client.get("/api/tags/directory?limit=nan")
|
resp = await client.get("/api/tags/directory?limit=nan")
|
||||||
assert resp.status_code == 400
|
assert resp.status_code == 400
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_directory_invalid_kind_is_400_not_500(client):
|
||||||
|
# 'copyright' is not a TagKind member; the route must reject it
|
||||||
|
# cleanly (400) instead of letting the enum cast 500.
|
||||||
|
resp = await client.get("/api/tags/directory?kind=copyright")
|
||||||
|
assert resp.status_code == 400
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_directory_valid_kind_ok(client, db):
|
||||||
|
db.add(Tag(name="a_fandom", kind=TagKind.fandom))
|
||||||
|
await db.flush()
|
||||||
|
await db.commit()
|
||||||
|
resp = await client.get("/api/tags/directory?kind=fandom&limit=10")
|
||||||
|
assert resp.status_code == 200
|
||||||
|
body = await resp.get_json()
|
||||||
|
assert any(c["name"] == "a_fandom" for c in body["cards"])
|
||||||
|
|||||||
Reference in New Issue
Block a user