Skip to content

hotfix: 공모전 슬라이드 빈 필터를 정규화 이후에 수행#122

Merged
selnem merged 1 commit into
developfrom
hotfix/AttributeError
Jun 14, 2026
Merged

hotfix: 공모전 슬라이드 빈 필터를 정규화 이후에 수행#122
selnem merged 1 commit into
developfrom
hotfix/AttributeError

Conversation

@selnem

@selnem selnem commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

Summary
공모전 카드뉴스 렌더링 중 prepare_contest_slides가 슬라이드 정규화 전에 빈 슬라이드 여부를 판단하여, LLM이 반환한 items 형식에 따라 오류 또는 슬라이드 누락이 발생할 수 있는 문제를 수정합니다.

prepare_contest_slides: normalize_contest_slide_copy 적용 후 is_contest_slide_empty로 필터링하도록 순서 변경
is_contest_slide_empty: items에 문자열이 포함된 경우 AttributeError가 발생하지 않도록 방어 처리 추가
value / content 키만 있는 항목이 정규화 전에 빈 슬라이드로 잘못 제외되던 문제 해소

배경
prepare_contest_slides에서 리스트 컴프리헨션 필터가 정규화보다 먼저 실행되어, 원본 슬라이드에 대해 is_contest_slide_empty가 호출되고 있었습니다.

items에 문자열이 포함되면 i.get("text") 호출 시 AttributeError로 렌더링 파이프라인이 중단될 수 있음
{"value": "..."} 형태 항목은 정규화 전에는 텍스트가 없는 것으로 판단되어 유효한 슬라이드가 누락될 수 있음

prepare_contest_slides에서 is_contest_slide_empty가 원본 슬라이드에 먼저 호출되어
items에 문자열이 있으면 AttributeError가 발생할 수 있고, value/content 키 항목이
비어 있다고 잘못 판단될 수 있었다. normalize_contest_slide_copy 후 필터링하도록
순서를 바꾸고, is_contest_slide_empty의 items 판별에 문자열 방어 처리를 추가한다.
@selnem selnem self-assigned this Jun 14, 2026
@selnem selnem added the 🐞 bug 버그 수정 label Jun 14, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the empty-slide detection logic in app/contest_cardnews/copy.py to handle non-dictionary items and ensures slides are normalized before checking if they are empty. The reviewer identified a potential bug where None values in slide['items'] could be incorrectly evaluated as non-empty due to str(None) returning "None". They suggested using not any(...) with a None check to improve both correctness and performance.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +140 to +143
return len([
i for i in slide["items"]
if (str(i.get("text") or "").strip() if isinstance(i, dict) else str(i).strip())
]) == 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

이슈: None 값에 대한 오탐지 가능성 및 비효율적인 리스트 컴프리헨션 사용

  1. None 처리 시의 버그: 만약 slide['items']None 원소가 포함되어 있다면, isinstance(None, dict)False가 되어 str(None).strip()이 실행됩니다. 파이썬에서 str(None)"None"이라는 빈 문자열이 아닌 값(truthy)을 반환하므로, 실제로는 비어 있는 슬라이드임에도 비어 있지 않은 것으로 잘못 판단하게 됩니다.
  2. 성능 및 가독성: len([x for x in ...]) == 0 방식은 조건에 맞는 모든 요소를 메모리에 리스트로 생성하므로 비효율적입니다. not any(...)를 사용하면 조건에 맞는 요소를 찾는 즉시 단락 평가(short-circuiting)가 이루어져 성능상 유리하고 가독성도 좋습니다.

제안

not any(...)를 사용하고 i is not None 조건을 추가하여 안전하고 효율적으로 빈 항목 여부를 검사하도록 개선합니다.

Suggested change
return len([
i for i in slide["items"]
if (str(i.get("text") or "").strip() if isinstance(i, dict) else str(i).strip())
]) == 0
return not any(
str(i.get("text") or "").strip() if isinstance(i, dict) else str(i).strip()
for i in slide["items"]
if i is not None
)

@selnem selnem merged commit 21d8a9e into develop Jun 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug 버그 수정

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant