fix: 2026-10-15 코드 검토 F01~F10 — 수집 실패 전파·트랜잭션 경계·저장 실패·공지 버전/확인 조건·테스트 체계
- F01 쿠팡: HTTP 200 비JSON·data 목록 없음은 수집 실패(기간 교체 안 함), 정상 빈 목록과 구분 - F02 회의록 [적용]: 업무 INSERT 와 줄 연결을 한 연결·한 트랜잭션(_insert_task), 확인은 잠그기 전·알림/메일은 커밋 뒤, 줄 바뀜 409 - F03 업무 등록 표: persist 실패 전파, 미저장이면 [적용] 중단, 초안 유지·다시 저장·이탈 경고 - F04 인증정보 변경 시 내부 토큰 삭제 + 네이버·토스 토큰을 발급 인증정보 지문(SHA-256)에 묶음, GS샵 방식 캐시도 키 지문 기준 - F05 쪽 수 상한·커서 반복 = 실패(쿠팡은 구간을 하루까지 나눠 재시도), 네이버·카카오·토스·GS샵 동일 기준 - F06 [중지] 확인과 저장 시작을 같은 잠금(begin_saving), 저장 시작 뒤 중지 불가 - F07/F08 긴급 공지: 내용 version·고친 공지 다시 그리기·확인에 version(409), 확인은 행 잠금 트랜잭션에서 수신자·표시 시각·취소 검증 - F09 쇼핑몰 연결 테스트도 clear 처리·저장 안 한 시험은 상태 유지(광고 테스트와 같은 계약) - F10 DB 테스트 skip·가짜 app.main/time.sleep 파일 범위 fixture, 오래된 기대값 갱신, pytest.ini·requirements-dev·tests/js/package.json·docs/TESTING.md - 결과·후속 과제: docs/CODE_REVIEW_2026-10-15_RESULT.md (마이그레이션·환경변수 변경 없음) Python 440 passed/63 skipped(DB 없음), 503 passed(로컬 PostgreSQL), jsdom 7종·Edge 6종 통과 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+113
-80
@@ -680,6 +680,28 @@ class ProjectStore:
|
||||
assignee_allowed: Any = None,
|
||||
) -> dict[str, Any]:
|
||||
"""assignee_allowed — update_task 와 같이 섹션 기본 담당자 자동 배정 전 지금 권한 확인(라우터가 넘김)."""
|
||||
with self._pool.connection() as conn:
|
||||
with conn.transaction():
|
||||
row, done_at = self._insert_task(
|
||||
conn, project_id=project_id, title=title, stage_id=stage_id, description=description,
|
||||
assignee_email=assignee_email, assignee_name=assignee_name, priority=priority,
|
||||
start_date=start_date, due_date=due_date, start_time=start_time, due_time=due_time,
|
||||
created_by=created_by, parent_task_id=parent_task_id, assignee_allowed=assignee_allowed,
|
||||
)
|
||||
out = self.get_task(task_id=row["id"])
|
||||
out["_newly_completed"] = done_at is not None
|
||||
return out
|
||||
|
||||
def _insert_task(
|
||||
self, conn: Any, *, project_id: int, title: str, stage_id: int | None = None, description: str = "",
|
||||
assignee_email: str = "", assignee_name: str = "", priority: str = "normal",
|
||||
start_date: str | None = None, due_date: str | None = None, start_time: str | None = None,
|
||||
due_time: str | None = None, created_by: str = "", parent_task_id: int | None = None,
|
||||
assignee_allowed: Any = None,
|
||||
) -> tuple[dict[str, Any], Any]:
|
||||
"""업무 한 건 INSERT(+배정·완료 이력) — **부르는 쪽의 연결·트랜잭션 안에서**(커밋하지 않음). (행, 완료 시각|None).
|
||||
create_task 와 회의록 [적용](apply_meeting_task — 줄 잠금과 같은 트랜잭션)이 같이 쓴다. 다른 풀 연결을 빌리지
|
||||
않는다(assignee_allowed 는 사용자 목록만 보는 함수)."""
|
||||
ttl = store.validate_task_title(title)
|
||||
pr = store.validate_priority(priority)
|
||||
sd = store.validate_date(start_date)
|
||||
@@ -689,74 +711,70 @@ class ProjectStore:
|
||||
store.validate_date_range(sd, dd, sti, dti)
|
||||
assignee = store.norm_str(assignee_email, lower=True)
|
||||
done_at = None
|
||||
with self._pool.connection() as conn:
|
||||
with conn.transaction():
|
||||
if parent_task_id is not None:
|
||||
# 세부 업무는 부모와 같은 프로젝트에 속하고(담당자 선택지 등이
|
||||
# 맞아떨어지게), 보드에는 안 보이므로 세션을 갖지 않는다.
|
||||
parent = conn.execute(
|
||||
"SELECT project_id FROM tasks WHERE id = %s", (parent_task_id,)
|
||||
).fetchone()
|
||||
if not parent:
|
||||
raise KeyError(f"상위 업무를 찾을 수 없습니다: {parent_task_id}")
|
||||
# 권한은 URL 의 project_id 로 검사했으므로, 부모가 다른 프로젝트
|
||||
# 업무면 거부한다(예전엔 부모 프로젝트로 조용히 바꿔 권한 없는
|
||||
# 프로젝트에 세부 업무를 만들 수 있었다).
|
||||
if int(parent["project_id"]) != int(project_id):
|
||||
raise ValueError("상위 업무가 이 프로젝트에 속하지 않습니다.")
|
||||
stage_id = None
|
||||
elif stage_id not in (None, ""):
|
||||
stage_id = self._check_stage_in_project(conn, stage_id, project_id)
|
||||
else:
|
||||
# stage 미지정 시 프로젝트의 첫 세션으로
|
||||
st = conn.execute(
|
||||
"SELECT id FROM project_stages WHERE project_id = %s "
|
||||
"ORDER BY sort_order ASC, id ASC LIMIT 1",
|
||||
(project_id,),
|
||||
).fetchone()
|
||||
stage_id = st["id"] if st else None
|
||||
# 담당자 없이 만들면 그 세션의 기본 담당자를 배정(세부 업무는
|
||||
# 세션이 없어 해당 없음).
|
||||
if not assignee and stage_id is not None:
|
||||
assignee, assignee_name = self._stage_default_assignee(conn, stage_id, project_id,
|
||||
allowed=assignee_allowed)
|
||||
# 완료 섹션에 바로 만든 작업은 완료 섹션으로 옮긴 것과 같이 완료 처리(완료 시각·이력).
|
||||
if stage_id is not None:
|
||||
done_row = conn.execute(
|
||||
"SELECT is_done_stage FROM project_stages WHERE id = %s", (stage_id,)
|
||||
).fetchone()
|
||||
if done_row and done_row["is_done_stage"]:
|
||||
done_at = now_kst()
|
||||
nxt = conn.execute(
|
||||
"SELECT COALESCE(MAX(sort_order), -1) + 1 AS n FROM tasks "
|
||||
"WHERE project_id = %s",
|
||||
(project_id,),
|
||||
).fetchone()
|
||||
row = conn.execute(
|
||||
"""
|
||||
INSERT INTO tasks
|
||||
(project_id, stage_id, parent_task_id, title, description,
|
||||
assignee_email, assignee_name, priority, start_date, due_date,
|
||||
start_time, due_time, sort_order, created_by, completed_at)
|
||||
VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
|
||||
RETURNING *
|
||||
""",
|
||||
(
|
||||
project_id, stage_id, parent_task_id, ttl, store.norm_str(description),
|
||||
assignee, store.norm_str(assignee_name), pr, sd, dd,
|
||||
sti, dti, int(nxt["n"]), store.norm_str(created_by, lower=True), done_at,
|
||||
),
|
||||
).fetchone()
|
||||
if assignee:
|
||||
self._log(conn, project_id=project_id, task_id=row["id"],
|
||||
actor=created_by, action=store.ACTION_ASSIGNED,
|
||||
detail=f"{ttl} → {assignee}")
|
||||
if done_at is not None:
|
||||
self._log(conn, project_id=project_id, task_id=row["id"],
|
||||
actor=created_by, action=store.ACTION_COMPLETED, detail=ttl)
|
||||
out = self.get_task(task_id=row["id"])
|
||||
out["_newly_completed"] = done_at is not None
|
||||
return out
|
||||
if parent_task_id is not None:
|
||||
# 세부 업무는 부모와 같은 프로젝트에 속하고(담당자 선택지 등이
|
||||
# 맞아떨어지게), 보드에는 안 보이므로 세션을 갖지 않는다.
|
||||
parent = conn.execute(
|
||||
"SELECT project_id FROM tasks WHERE id = %s", (parent_task_id,)
|
||||
).fetchone()
|
||||
if not parent:
|
||||
raise KeyError(f"상위 업무를 찾을 수 없습니다: {parent_task_id}")
|
||||
# 권한은 URL 의 project_id 로 검사했으므로, 부모가 다른 프로젝트
|
||||
# 업무면 거부한다(예전엔 부모 프로젝트로 조용히 바꿔 권한 없는
|
||||
# 프로젝트에 세부 업무를 만들 수 있었다).
|
||||
if int(parent["project_id"]) != int(project_id):
|
||||
raise ValueError("상위 업무가 이 프로젝트에 속하지 않습니다.")
|
||||
stage_id = None
|
||||
elif stage_id not in (None, ""):
|
||||
stage_id = self._check_stage_in_project(conn, stage_id, project_id)
|
||||
else:
|
||||
# stage 미지정 시 프로젝트의 첫 세션으로
|
||||
st = conn.execute(
|
||||
"SELECT id FROM project_stages WHERE project_id = %s "
|
||||
"ORDER BY sort_order ASC, id ASC LIMIT 1",
|
||||
(project_id,),
|
||||
).fetchone()
|
||||
stage_id = st["id"] if st else None
|
||||
# 담당자 없이 만들면 그 세션의 기본 담당자를 배정(세부 업무는
|
||||
# 세션이 없어 해당 없음).
|
||||
if not assignee and stage_id is not None:
|
||||
assignee, assignee_name = self._stage_default_assignee(conn, stage_id, project_id,
|
||||
allowed=assignee_allowed)
|
||||
# 완료 섹션에 바로 만든 작업은 완료 섹션으로 옮긴 것과 같이 완료 처리(완료 시각·이력).
|
||||
if stage_id is not None:
|
||||
done_row = conn.execute(
|
||||
"SELECT is_done_stage FROM project_stages WHERE id = %s", (stage_id,)
|
||||
).fetchone()
|
||||
if done_row and done_row["is_done_stage"]:
|
||||
done_at = now_kst()
|
||||
nxt = conn.execute(
|
||||
"SELECT COALESCE(MAX(sort_order), -1) + 1 AS n FROM tasks "
|
||||
"WHERE project_id = %s",
|
||||
(project_id,),
|
||||
).fetchone()
|
||||
row = conn.execute(
|
||||
"""
|
||||
INSERT INTO tasks
|
||||
(project_id, stage_id, parent_task_id, title, description,
|
||||
assignee_email, assignee_name, priority, start_date, due_date,
|
||||
start_time, due_time, sort_order, created_by, completed_at)
|
||||
VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
|
||||
RETURNING *
|
||||
""",
|
||||
(
|
||||
project_id, stage_id, parent_task_id, ttl, store.norm_str(description),
|
||||
assignee, store.norm_str(assignee_name), pr, sd, dd,
|
||||
sti, dti, int(nxt["n"]), store.norm_str(created_by, lower=True), done_at,
|
||||
),
|
||||
).fetchone()
|
||||
if assignee:
|
||||
self._log(conn, project_id=project_id, task_id=row["id"],
|
||||
actor=created_by, action=store.ACTION_ASSIGNED,
|
||||
detail=f"{ttl} → {assignee}")
|
||||
if done_at is not None:
|
||||
self._log(conn, project_id=project_id, task_id=row["id"],
|
||||
actor=created_by, action=store.ACTION_COMPLETED, detail=ttl)
|
||||
return row, done_at
|
||||
|
||||
def move_subtask(
|
||||
self, *, task_id: int, parent_task_id: int, actor: str = ""
|
||||
@@ -3735,11 +3753,20 @@ class ProjectStore:
|
||||
return self._mt_row(row)
|
||||
return self._mt_call(run)
|
||||
|
||||
def apply_meeting_task(self, *, item_id: int, create: Any) -> tuple[dict[str, Any], bool]:
|
||||
"""[적용] — 줄을 잠그고 아직 작업이 없을 때만 create(줄, 상위 작업 id) 로 작업을 만들어 task_id 를 남긴다.
|
||||
작업 칸(parent_task_id)을 골랐으면 그 작업의 세부 작업으로(섹션 없이). (줄, 이번에 만들었는가).
|
||||
두 사람이 동시에 눌러도 작업은 하나. create 가 실패하면 줄은 그대로."""
|
||||
def run() -> tuple[int, bool]:
|
||||
# [적용] 때 라우터가 권한·담당자를 확인한 줄 값 — 잠근 뒤 이 값이 그대로여야 만든다(그사이 고쳐졌으면 409)
|
||||
MT_APPLY_KEYS = ("title", "project_id", "stage_id", "assignee_email", "parent_task_id")
|
||||
|
||||
def apply_meeting_task(self, *, item_id: int, task_fields: dict[str, Any] | None,
|
||||
expect: dict[str, Any] | None = None) -> tuple[dict[str, Any], bool, dict[str, Any] | None]:
|
||||
"""[적용] — 줄을 잠그고 아직 업무가 없을 때만 업무를 만들어 task_id 를 남긴다. **업무 INSERT 와 줄 연결이 같은 연결·
|
||||
같은 트랜잭션**이라(2026-10-15 검토 F02) 연결 기록이 실패하면 업무도 롤백되고, 재시도·동시 클릭에도 업무는 하나다.
|
||||
트랜잭션 안에서는 이 연결 하나만 쓴다(같은 풀의 다른 연결을 기다리지 않음).
|
||||
|
||||
task_fields = _insert_task 인자(라우터가 잠그기 전에 권한·담당자를 확인해 만든 값, project_id·parent_task_id 포함).
|
||||
expect = 그 확인에 쓴 줄(get_meeting_task) — 잠근 줄의 MT_APPLY_KEYS 가 다르면 GoalCellConflict(다시 [적용]).
|
||||
작업 칸(parent_task_id)이면 그 업무의 세부 업무(섹션 없음) — 상위 업무가 같은 프로젝트에 아직 있는지 잠근 뒤 다시 본다.
|
||||
돌려주는 값: (줄, 이번에 만들었는가, 만든 업무|None). 알림·메일은 라우터가 커밋 뒤에."""
|
||||
def run() -> tuple[int, bool, tuple[int, Any] | None]:
|
||||
with self._mt_conn() as conn:
|
||||
with conn.transaction():
|
||||
row = conn.execute(f"SELECT {self._mt_cols(conn)} FROM goal_meeting_tasks WHERE id = %s FOR UPDATE",
|
||||
@@ -3748,20 +3775,26 @@ class ProjectStore:
|
||||
raise KeyError(item_id)
|
||||
self._check_meeting_open(conn, row["week_start"])
|
||||
if row["task_id"] is not None:
|
||||
return item_id, False
|
||||
return item_id, False, None
|
||||
use = self._mt_row(row)
|
||||
if task_fields is None or (expect is not None and any(
|
||||
use.get(k) != expect.get(k) for k in self.MT_APPLY_KEYS)):
|
||||
raise store.GoalCellConflict("그사이 줄이 바뀌었습니다. 새로고침한 뒤 다시 [적용]해 주세요.")
|
||||
parent_task = use.get("parent_task_id")
|
||||
if parent_task is not None:
|
||||
t = conn.execute("SELECT project_id FROM tasks WHERE id = %s", (parent_task,)).fetchone()
|
||||
if t is None or use["project_id"] is None or int(t["project_id"]) != int(use["project_id"]):
|
||||
raise ValueError("고른 업무가 없어졌거나 다른 프로젝트로 옮겨졌습니다. 업무 칸을 다시 고르세요.")
|
||||
use = {**use, "stage_id": None}
|
||||
task = create(use, parent_task)
|
||||
task_row, done_at = self._insert_task(conn, **task_fields)
|
||||
conn.execute("UPDATE goal_meeting_tasks SET task_id = %s, updated_at = now() WHERE id = %s",
|
||||
(int(task["id"]), item_id))
|
||||
return item_id, True
|
||||
iid, made = self._mt_call(run)
|
||||
return self.get_meeting_task(item_id=iid), made # type: ignore[return-value]
|
||||
(int(task_row["id"]), item_id))
|
||||
return item_id, True, (int(task_row["id"]), done_at)
|
||||
iid, made, info = self._mt_call(run)
|
||||
task = None
|
||||
if info is not None:
|
||||
task = self.get_task(task_id=info[0])
|
||||
task["_newly_completed"] = info[1] is not None
|
||||
return self.get_meeting_task(item_id=iid), made, task # type: ignore[return-value]
|
||||
|
||||
def goal_month_targets(self, *, year: int, month: int) -> dict[str, Any]:
|
||||
"""회의록 머리 — 그 달 매출 목표·실적, 로아스 목표(목표 표 숫자), 매출 단위. 목표 표가 없으면 빈 값."""
|
||||
|
||||
Reference in New Issue
Block a user