Skip to content

Log warning on KeyError when linking illustration token to novel progress entry#154

Merged
CyberSecDef merged 2 commits into
mainfrom
copilot/fix-silent-keyerror-illustration-progress-update
Apr 8, 2026
Merged

Log warning on KeyError when linking illustration token to novel progress entry#154
CyberSecDef merged 2 commits into
mainfrom
copilot/fix-silent-keyerror-illustration-progress-update

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 8, 2026

When a novel's progress entry is deleted mid-flight, progress_manager.update raises KeyError that was silently swallowed — leaving an orphaned image on disk with no way for the UI to surface it.

Changes

  • novelforge/routes/export.py: Replace except KeyError: pass with a logger.warning that includes the missing progress token, making the failure observable in logs.
# Before
except KeyError:
    pass

# After
except KeyError:
    logger.warning(
        "Could not link illustration to novel (progress entry %s not found).",
        token,
    )
  • tests/test_illustration_job.py: Add test_warning_logged_when_novel_progress_entry_missing — patches progress_manager.update to raise KeyError on the link call and asserts the warning is emitted via caplog.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.openai.com
    • Triggering command: /usr/bin/python python -m pytest --tb=short -q (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested review from Copilot and removed request for Copilot April 8, 2026 20:50
Copilot AI linked an issue Apr 8, 2026 that may be closed by this pull request
…ion progress update

Agent-Logs-Url: https://github.com/CyberSecDef/NovelForge/sessions/2af5748d-8349-42e2-8634-75f051258adf

Co-authored-by: CyberSecDef <17597068+CyberSecDef@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot April 8, 2026 20:54
Copilot AI changed the title [WIP] Fix silent KeyError in Illustration Progress Update Log warning on KeyError when linking illustration token to novel progress entry Apr 8, 2026
Copilot AI requested a review from CyberSecDef April 8, 2026 20:55
@CyberSecDef CyberSecDef marked this pull request as ready for review April 8, 2026 21:01
Copilot AI review requested due to automatic review settings April 8, 2026 21:01
@CyberSecDef CyberSecDef merged commit ae3c985 into main Apr 8, 2026
8 of 10 checks passed
@CyberSecDef CyberSecDef deleted the copilot/fix-silent-keyerror-illustration-progress-update branch April 8, 2026 21:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR makes illustration-linking failures observable by logging a warning when the novel progress entry disappears (raising KeyError) during /generate_illustrations, and adds a regression test to ensure the warning is emitted.

Changes:

  • Replace a silent except KeyError: pass with a logger.warning(...) in the illustration generation route.
  • Add a pytest case that simulates progress_manager.update raising KeyError and asserts a warning is logged via caplog.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
novelforge/routes/export.py Logs a warning when the novel progress entry is missing during illustration token linking.
tests/test_illustration_job.py Adds a test to verify the warning is emitted when the linking update raises KeyError.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

data=json.dumps({"token": token}),
content_type="application/json")

warning_msgs = [r.message for r in caplog.records if r.levelno == logging.WARNING]
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

caplog.records contains logging.LogRecord objects, which don’t reliably have a .message attribute populated. This can raise AttributeError or produce unformatted text depending on how pytest formats records. Prefer caplog.messages or record.getMessage() when building warning_msgs so the assertion is stable.

Suggested change
warning_msgs = [r.message for r in caplog.records if r.levelno == logging.WARNING]
warning_msgs = [r.getMessage() for r in caplog.records if r.levelno == logging.WARNING]

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Silent KeyError in Illustration Progress Update

3 participants