Skip to content

Commit 571e5eb

Browse files
authored
Correct message when is_generating hits 500 code (#2889)
1 parent 21820f4 commit 571e5eb

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
## Bug Fixes:
77
* Fixed bug where setting `default_enabled=False` made it so that the entire queue did not start by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2876](https://github.com/gradio-app/gradio/pull/2876)
8+
* Fixed bug where an error raised after yielding iterative output would not be displayed in the browser by
9+
[@JaySmithWpg](https://github.com/JaySmithWpg) in [PR 2889](https://github.com/gradio-app/gradio/pull/2889)
810

911
## Documentation Changes:
1012
* Added a Guide on using Google Sheets to create a real-time dashboard with Gradio's `DataFrame` and `LinePlot` component, by [@abidlabs](https://github.com/abidlabs) in [PR 2816](https://github.com/gradio-app/gradio/pull/2816)

gradio/queue.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,17 @@ async def process_events(self, events: List[Event], batch: bool) -> None:
330330
return
331331
response = await self.call_prediction(awake_events, batch)
332332
for event in awake_events:
333+
if response.status != 200:
334+
relevant_response = response
335+
else:
336+
relevant_response = old_response
337+
333338
await self.send_message(
334339
event,
335340
{
336341
"msg": "process_completed",
337-
"output": old_response.json,
338-
"success": old_response.status == 200,
342+
"output": relevant_response.json,
343+
"success": relevant_response.status == 200,
339344
},
340345
)
341346
else:

test/test_queue.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,38 @@ async def test_process_event_handles_exception_in_call_prediction_request(
223223
mock_event.disconnect.assert_called_once()
224224
assert queue.clean_event.call_count >= 1
225225

226+
@pytest.mark.asyncio
227+
async def test_process_event_handles_exception_in_is_generating_request(
228+
self, queue: Queue, mock_event: Event
229+
):
230+
# We need to return a good response with is_generating=True first,
231+
# setting up the function to expect further iterative responses.
232+
# Then we provide a 500 response.
233+
side_effects = [
234+
MagicMock(has_exception=False, status=200, json=dict(is_generating=True)),
235+
MagicMock(has_exception=False, status=500, json=dict(error="Foo")),
236+
]
237+
mock_event.disconnect = AsyncMock()
238+
queue.gather_event_data = AsyncMock(return_value=True)
239+
queue.clean_event = AsyncMock()
240+
queue.send_message = AsyncMock(return_value=True)
241+
queue.call_prediction = AsyncMock(side_effect=side_effects)
242+
243+
queue.active_jobs = [[mock_event]]
244+
await queue.process_events([mock_event], batch=False)
245+
queue.send_message.assert_called_with(
246+
mock_event,
247+
{
248+
"msg": "process_completed",
249+
"output": {"error": "Foo"},
250+
"success": False,
251+
},
252+
)
253+
254+
assert queue.call_prediction.call_count == 2
255+
mock_event.disconnect.assert_called_once()
256+
assert queue.clean_event.call_count >= 1
257+
226258
@pytest.mark.asyncio
227259
async def test_process_event_handles_error_sending_process_completed_msg(
228260
self, queue: Queue, mock_event: Event

0 commit comments

Comments
 (0)