Log warning on KeyError when linking illustration token to novel progress entry#154
Conversation
…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>
There was a problem hiding this comment.
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: passwith alogger.warning(...)in the illustration generation route. - Add a pytest case that simulates
progress_manager.updateraisingKeyErrorand asserts a warning is logged viacaplog.
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] |
There was a problem hiding this comment.
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.
| 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] |
When a novel's progress entry is deleted mid-flight,
progress_manager.updateraisesKeyErrorthat was silently swallowed — leaving an orphaned image on disk with no way for the UI to surface it.Changes
novelforge/routes/export.py: Replaceexcept KeyError: passwith alogger.warningthat includes the missing progress token, making the failure observable in logs.tests/test_illustration_job.py: Addtest_warning_logged_when_novel_progress_entry_missing— patchesprogress_manager.updateto raiseKeyErroron the link call and asserts the warning is emitted viacaplog.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/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: