api fixes. CHAT container NEEDS ATTENTION
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
41
scripts/fix_match_response_models.sh
Executable file
41
scripts/fix_match_response_models.sh
Executable file
@@ -0,0 +1,41 @@
|
||||
set -euo pipefail
|
||||
DIR="services/match/src/app/schemas"
|
||||
[ -d "$DIR" ] || { echo "Not found: $DIR"; exit 1; }
|
||||
|
||||
python3 - "$DIR" <<'PY'
|
||||
from pathlib import Path
|
||||
import re, sys
|
||||
d = Path(sys.argv[1])
|
||||
for p in d.glob("*.py"):
|
||||
s = p.read_text(); orig = s
|
||||
if "class " not in s:
|
||||
continue
|
||||
|
||||
if "from uuid import UUID" not in s:
|
||||
s = "from uuid import UUID\n" + s
|
||||
|
||||
# самые частые поля
|
||||
s = re.sub(r'(\bid\s*:\s*)str', r'\1UUID', s)
|
||||
s = re.sub(r'(\buser_id_a\s*:\s*)str', r'\1UUID', s)
|
||||
s = re.sub(r'(\buser_id_b\s*:\s*)str', r'\1UUID', s)
|
||||
s = re.sub(r'(\buser_id\s*:\s*)str', r'\1UUID', s)
|
||||
|
||||
# включаем from_attributes / orm_mode для Out/Response моделей
|
||||
def patch_block(m):
|
||||
block = m.group(0)
|
||||
if "model_config" in block or "orm_mode" in block:
|
||||
return block
|
||||
return (block +
|
||||
"\n try:\n from pydantic import ConfigDict\n model_config = ConfigDict(from_attributes=True)\n"
|
||||
" except Exception:\n class Config:\n orm_mode = True\n")
|
||||
|
||||
s = re.sub(r"class\s+\w+(Out|Response)\s*\([^\)]*\)\s*:(?:\n\s+.+)+", patch_block, s)
|
||||
|
||||
if s != orig:
|
||||
p.write_text(s)
|
||||
print("[match] Patched:", p)
|
||||
PY
|
||||
|
||||
echo "[match] Rebuild & restart…"
|
||||
docker compose build match
|
||||
docker compose restart match
|
||||
Reference in New Issue
Block a user