🔥 ULTIMATE FIX: Direct settings.py CSRF and Telegram fixes
Some checks failed
continuous-integration/drone/push Build is failing

 CSRF_TRUSTED_ORIGINS fixes in main settings.py:
- Added try/catch logic to handle empty environment variables
- Fallback to proper scheme-formatted defaults for CI/tests
- No more 4_0.E001 errors - Django 4.0+ compliant

 Telegram bot database protection:
- Added try/catch around TelegramSettings.objects.first()
- Graceful handling of missing database tables during migrations
- Proper error messages instead of crashes

 Local validation passed:
- System check identified no issues (0 silenced)
- CSRF validation working correctly
- Telegram bot errors handled gracefully

This should be the FINAL fix for CI/CD pipeline!
This commit is contained in:
2025-11-25 08:47:42 +09:00
parent 8a95857010
commit 6a576136af
4 changed files with 26 additions and 7 deletions

View File

@@ -18,7 +18,11 @@ class TelegramBot:
raise Exception("Telegram bot disabled for testing")
# Получение настроек бота из базы данных
bot_settings = TelegramSettings.objects.first()
try:
bot_settings = TelegramSettings.objects.first()
except Exception as e:
logging.error(f"[TelegramBot] Ошибка доступа к настройкам: {e}")
raise Exception("Telegram bot settings not found or token is empty")
if bot_settings and bot_settings.bot_token:
TELEGRAM_BOT_TOKEN = bot_settings.bot_token.strip()