fix: image monitor recent-prompt fallback reads the paginated result
get_recent_prompts returns {"prompts": [...]} but _get_fallback_prompt
indexed it like a list, so the last-resort link to the most recent prompt
always failed silently. Accept both shapes.
This commit is contained in:
@@ -121,7 +121,9 @@ class TestMetadataLinking(LinkingTestCase):
|
||||
self.assertEqual(
|
||||
self.handler._find_prompt_from_metadata(metadata), ("unknown", None)
|
||||
)
|
||||
self.assertNotEqual(self._process(metadata), negative)
|
||||
latest = self._save("most recent prompt") # recency fallback picks this
|
||||
self.assertEqual(self._process(metadata), latest)
|
||||
self.assertNotEqual(latest, negative)
|
||||
|
||||
def test_workflow_fallback_still_used_without_an_api_graph(self):
|
||||
positive = self._save("from workflow only")
|
||||
@@ -221,6 +223,15 @@ class TestForeignWorkflows(LinkingTestCase):
|
||||
("unknown", None),
|
||||
)
|
||||
|
||||
def test_unknown_image_without_any_context_falls_back_to_the_latest_prompt(self):
|
||||
self._save("older")
|
||||
latest = self._save("latest")
|
||||
self.assertEqual(self._process(None), latest)
|
||||
|
||||
def test_recent_prompt_fallback_handles_an_empty_database(self):
|
||||
self.assertIsNone(self.handler._get_fallback_prompt())
|
||||
self.assertIsNone(self._process(None))
|
||||
|
||||
def test_metadata_lookup_errors_are_unknown(self):
|
||||
self._save("a cat")
|
||||
with mock.patch.object(
|
||||
|
||||
@@ -463,7 +463,11 @@ class ImageGenerationHandler(FileSystemEventHandler):
|
||||
or None if no recent prompt is available
|
||||
"""
|
||||
try:
|
||||
recent_prompts = self.db_manager.get_recent_prompts(limit=1)
|
||||
recent = self.db_manager.get_recent_prompts(limit=1)
|
||||
# Paginated dict ({"prompts": [...]}) or a plain list
|
||||
recent_prompts = (
|
||||
recent.get("prompts") if isinstance(recent, dict) else recent
|
||||
)
|
||||
if recent_prompts:
|
||||
prompt = recent_prompts[0]
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user