fix(image_gen): prevent double interaction defer in auto image style generation - #134
fix(image_gen): prevent double interaction defer in auto image style generation#134YoneRai12 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds a check to prevent double-deferring interactions in the start_generation method. The reviewer suggests refactoring the method to consistently use the passed interaction object instead of self.original_interaction to avoid potential expiration errors and improve maintainability.
| if not interaction.response.is_done(): | ||
| await interaction.response.defer() |
There was a problem hiding this comment.
この修正により、style_auto 経由で既に defer() が呼ばれている場合の二重応答エラー(InteractionResponded)を適切に回避できています。
改善の提案として、このメソッド内で引数の interaction と self.original_interaction(初期化時に保存されたもの)が混在して使用されている点に注意してください。32行目などの処理で self.original_interaction を使用していますが、これは古いインタラクションであるため、ユーザーがスタイル選択画面で長時間放置した場合などに期限切れ(15分)でエラーになるリスクがあります。
start_generation が引数の interaction の状態を保証するようになったため、メソッド全体でこの最新の interaction を一貫して使用するようにリファクタリングすることで、堅牢性と保守性が向上します。
Motivation
style_auto)が既にinteraction.response.defer()しているときに、共通処理start_generationが再度defer()を呼んでしまい、Discordの二重応答エラー(InteractionResponded)で自動生成フローが中断される問題を修正するため。Description
src/views/image_gen.pyのStyleSelectView.start_generationで、if not interaction.response.is_done(): await interaction.response.defer()というガードを追加して、既に応答済みのインタラクションに対しては二重でdefer()しないようにした。Testing
python -m py_compile src/views/image_gen.pyを実行して構文チェックが成功したことを確認した。deferが回避されることを確認した。Codex Task