Corp/backend/scripts/audit_code_patterns.sh
lizerk 2688df46ef Fix: Wrap all unsafe int() conversions with try/except
Fixed ValueError-prone int() calls in:
- communications/api/viewsets.py (4 places: limit, before_limit, after_limit)
- notifications/api/views.py (2 places: page, page_size)
- api/v1/search/views.py (1 place: limit)
- api/v1/procurement/views.py (1 place: quantity)
Also updated audit script to exclude .venv/
2026-03-20 09:10:33 +03:00

29 lines
1.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Аудит потенциально проблемных паттернов в коде
# Исключает .venv/ (сторонние пакеты)
echo "=== Поиск потенциальных проблем ==="
echo ""
echo "1. Небезопасный доступ к request.data:"
grep -rn "request\.data\[" --include="*.py" . --exclude-dir=.venv | grep -v "# noqa" || echo "✓ Не найдено"
echo ""
echo "2. Использование .dict() без проверки типа:"
grep -rn "\.data\.dict()" --include="*.py" . --exclude-dir=.venv | grep -v "hasattr" || echo "✓ Не найдено"
echo ""
echo "3. Прямое обращение к QueryDict без .get():"
grep -rn "request\.POST\[" --include="*.py" . --exclude-dir=.venv | grep -v "# noqa" || echo "✓ Не найдено"
echo ""
echo "4. Небезопасный int() без try/except:"
grep -rn "int(.*request\." --include="*.py" . --exclude-dir=.venv | head -20
echo ""
echo "5. Отсутствие проверки на None перед .strip():"
grep -rn "\.strip()" --include="*.py" . --exclude-dir=.venv | grep -v "if.*:" | head -10
echo ""
echo "=== Аудит завершен ==="