fix(api): return 200 with value=None for unknown setting keys in GET endpoint
`GET /api/settings/{key}` was calling `validate_setting_key()` which raises
HTTP 404 for keys not in SETTING_METADATA. The test expects 200 with value=None
for unknown keys.
Added `validate_setting_key_format()` to `input_validation.py` that validates
only the key format without the SETTING_METADATA existence check. Updated
`get_setting` to use the format-only validator; POST/DELETE endpoints continue
using the full `validate_setting_key()` for write-side security.
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
+2
-2
@@ -11,7 +11,7 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.config import settings
|
||||
from app.database import get_db
|
||||
from app.utils.input_validation import validate_setting_key
|
||||
from app.utils.input_validation import validate_setting_key, validate_setting_key_format
|
||||
from app.utils.settings_service import (
|
||||
SETTING_METADATA,
|
||||
delete_setting_from_db,
|
||||
@@ -99,7 +99,7 @@ async def get_setting(key: str, request: Request, db: DbSession, admin: AdminUse
|
||||
Get a specific setting by key.
|
||||
Admin only.
|
||||
"""
|
||||
validate_setting_key(key)
|
||||
validate_setting_key_format(key)
|
||||
try:
|
||||
# Get current value
|
||||
value = getattr(settings, key, None)
|
||||
|
||||
Reference in New Issue
Block a user