Add troubleshooting note for emotion interval SQL and Slack token fallback fix
This commit is contained in:
parent
05f49a5fae
commit
faeb97f24b
@ -0,0 +1,53 @@
|
|||||||
|
# rb8001 감정 interval SQL 및 Slack token fallback 수정
|
||||||
|
|
||||||
|
## 일시
|
||||||
|
- 분석/수정: 2026-03-03 (KST)
|
||||||
|
|
||||||
|
## 배경
|
||||||
|
- 로그에서 감정 조회 오류 반복:
|
||||||
|
- `Failed to query user emotion readings: invalid input syntax for type interval: "" + str(days) + " days""`
|
||||||
|
- Slack 이벤트 경로 간헐 오류:
|
||||||
|
- `No bot token provided in headers`
|
||||||
|
|
||||||
|
## 원인
|
||||||
|
1. 감정 조회 SQL 문자열 버그
|
||||||
|
- `app/state/database.py`의 2개 쿼리가 `INTERVAL '" + str(days) + " days'` 형태로 고정 문자열이 들어가도록 작성되어 있었음.
|
||||||
|
- PostgreSQL이 interval로 파싱하지 못해 예외 발생.
|
||||||
|
|
||||||
|
2. Slack 토큰 헤더 강제 의존
|
||||||
|
- `app/router/slack/events.py`(및 동일 로직의 `slack_handler.py`)가 `X-Slack-Bot-Token` 헤더가 없으면 즉시 400 반환.
|
||||||
|
- Gateway→rb8001 헤더 전달이 누락되는 순간 이벤트가 무응답으로 실패.
|
||||||
|
|
||||||
|
## 조치
|
||||||
|
1. 감정 SQL 파라미터화
|
||||||
|
- `created_at >= NOW() - ($2::int * INTERVAL '1 day')`로 변경.
|
||||||
|
- `conn.fetch(query, user_id, days)` 바인딩으로 전달.
|
||||||
|
|
||||||
|
2. Slack 토큰 fallback 추가
|
||||||
|
- 우선순위: `X-Slack-Bot-Token` 헤더 → `settings.SLACK_BOT_TOKEN`.
|
||||||
|
- 둘 다 없을 때만 400 반환.
|
||||||
|
- 비동기 context에 넣는 `bot_token`도 `effective_token`으로 통일.
|
||||||
|
|
||||||
|
## TDD 테스트
|
||||||
|
- 신규: `rb8001/tests/test_emotion_db_interval_query_tdd.py`
|
||||||
|
- interval이 파라미터 바인딩으로 전달되는지 검증.
|
||||||
|
- 신규: `rb8001/tests/test_slack_events_token_fallback.py`
|
||||||
|
- 헤더 없이 settings 토큰만 있어도 URL verification 200 검증.
|
||||||
|
- 헤더/설정 모두 없으면 400 검증.
|
||||||
|
|
||||||
|
실행 명령:
|
||||||
|
```bash
|
||||||
|
cd /home/admin/ivada_project/rb8001
|
||||||
|
PYTHONPATH=. JWT_SECRET_KEY=test-secret \
|
||||||
|
pytest -q tests/test_emotion_db_interval_query_tdd.py \
|
||||||
|
tests/test_slack_events_token_fallback.py \
|
||||||
|
tests/test_emotion_pattern_analysis.py
|
||||||
|
```
|
||||||
|
|
||||||
|
결과:
|
||||||
|
- `10 passed`
|
||||||
|
|
||||||
|
## 영향
|
||||||
|
- 감정 조회 interval 파싱 오류 제거.
|
||||||
|
- Gateway 헤더 누락 시 Slack 이벤트 완전 실패(400) 확률 감소.
|
||||||
|
- 멀티 워크스페이스 헤더 전달 구조는 유지하면서 운영 내구성만 보강.
|
||||||
Loading…
x
Reference in New Issue
Block a user