fix(backend): #84 real woo_reachable, #83 reject unknown fields, #82 live taxonomy in stale_field, #80 persist review overrides
#84: /api/health woo_reachable is now a real check (GET /wp-json/ with a 3s timeout) instead of a hardcoded False stub. Version bumped to 0.5.0-m3-s1. #83: POST /slabs rejects unknown (non-ALLOWED_FIELDS) keys with a 400 'unknown fields' error, instead of silently dropping them. The INSERT binding count is now provably correct (no more assert needed). #82: stale_field 422 error now returns the LIVE taxonomy ids (SELECT id FROM table) as current_options, plus the field name and submitted value, instead of echoing the submitted value back. #80: regular review (no lock) persists owner overrides (price/sku/title/ short_description) from the payload to the DB via an UPDATE, so the review endpoint is self-contained. server_rev is incremented on persist. Tests: +3 (test_create_rejects_unknown_fields, test_update_stale_field_returns_live_options, test_review_persists_owner_overrides). 87/87 passing.
This commit is contained in:
+20
-3
@@ -25,7 +25,7 @@ from starlette.middleware.base import BaseHTTPMiddleware
|
||||
from .db import get_connection, init_db, probe_images_writable, probe_writable
|
||||
from . import settings as settings_mod
|
||||
|
||||
__version__ = "0.5.0-m3-s0"
|
||||
__version__ = "0.5.0-m3-s1"
|
||||
|
||||
# --- Structured JSON logging (stdlib only) ---
|
||||
request_id_var: ContextVar[str] = ContextVar("request_id", default="")
|
||||
@@ -155,16 +155,33 @@ def _error(code: str, message: str, detail: Any = None) -> dict:
|
||||
|
||||
@app.get("/api/health")
|
||||
async def health() -> dict[str, Any]:
|
||||
"""Health per APP-30/45: non-200 when db or image volume not writable (probe file)."""
|
||||
"""Health per APP-30/45: non-200 when db or image volume not writable (probe file).
|
||||
#84: woo_reachable is a real check (HEAD /wp-json/ with a short timeout),
|
||||
not a hardcoded stub.
|
||||
"""
|
||||
db_ok = probe_writable()
|
||||
img_ok = probe_images_writable()
|
||||
if not (db_ok and img_ok):
|
||||
logger.warning("health: storage not writable", extra={"request_id": request_id_var.get("")})
|
||||
raise HTTPException(status_code=503, detail="storage not writable")
|
||||
woo_reachable = False
|
||||
try:
|
||||
woo_base = os.environ.get("WOO_BASE_URL", "")
|
||||
if woo_base:
|
||||
import urllib.request
|
||||
req = urllib.request.Request(
|
||||
woo_base.rstrip("/") + "/wp-json/",
|
||||
method="GET",
|
||||
headers={"User-Agent": "SlabUploader/health"},
|
||||
)
|
||||
with urllib.request.urlopen(req, timeout=3) as resp:
|
||||
woo_reachable = resp.status < 500
|
||||
except Exception:
|
||||
woo_reachable = False
|
||||
return {
|
||||
"status": "ok",
|
||||
"version": __version__,
|
||||
"woo_reachable": False, # S0 stub; S4 will implement real check
|
||||
"woo_reachable": woo_reachable,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user