From 4de48eea190679a09ec34af825bbbead1b91ad83 Mon Sep 17 00:00:00 2001 From: Em Zhan Date: Tue, 26 Mar 2024 22:34:16 -0500 Subject: [PATCH] fix #485: avoid crash due to duplicate screen id (#486) --- CHANGELOG.md | 4 ++++ src/harlequin/app.py | 2 +- tests/functional_tests/test_history_screen.py | 20 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a709de97..d37b6d94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Bug Fixes + +- Pressing `F8` on the history screen no longer causes a crash ([#485](https://github.com/tconbeer/harlequin/issues/485)) + ## [1.16.0] - 2024-02-22 ### Changes diff --git a/src/harlequin/app.py b/src/harlequin/app.py index 62d20d22..514ccd64 100644 --- a/src/harlequin/app.py +++ b/src/harlequin/app.py @@ -611,7 +611,7 @@ async def history_callback(screen_data: str) -> None: "Please wait a moment and try again." ), ) - else: + elif self.screen.id != "history_screen": self.push_screen( HistoryScreen( history=self.history, diff --git a/tests/functional_tests/test_history_screen.py b/tests/functional_tests/test_history_screen.py index 3a5075fb..a56058cc 100644 --- a/tests/functional_tests/test_history_screen.py +++ b/tests/functional_tests/test_history_screen.py @@ -57,3 +57,23 @@ async def test_history_screen( snap_results.append(await app_snapshot(app, "New buffer with select 14")) assert all(snap_results) + + +@pytest.mark.asyncio +async def test_history_screen_crash( + app: Harlequin, + app_snapshot: Callable[..., Awaitable[bool]], + mock_time: None, +) -> None: + async with app.run_test() as pilot: + q = "\n".join([f"select {i};" for i in range(15)]) + while app.editor is None: + await pilot.pause() + app.post_message(QuerySubmitted(query_text=q, limit=None)) + await pilot.pause() + await app.workers.wait_for_complete() + await pilot.pause() + + # https://github.com/tconbeer/harlequin/issues/485 + await pilot.press("f8") + await pilot.press("f8")