From 46b33492c5bc19ef264995c9ea351f584cbb90b4 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Sat, 21 Mar 2026 19:50:16 +0100 Subject: [PATCH] `last_error` should be cleared if page content was the same and there was no error --- changedetectionio/tests/test_backend.py | 25 +++++++++++++++++++++++++ changedetectionio/worker.py | 3 +++ 2 files changed, 28 insertions(+) diff --git a/changedetectionio/tests/test_backend.py b/changedetectionio/tests/test_backend.py index c523999d..d0713133 100644 --- a/changedetectionio/tests/test_backend.py +++ b/changedetectionio/tests/test_backend.py @@ -422,3 +422,28 @@ def test_plaintext_even_if_xml_content_and_can_apply_filters(client, live_server assert b'<foobar' not in res.data res = delete_all_watches(client) + + +def test_last_error_cleared_on_same_checksum(client, live_server, datastore_path): + """last_error should be cleared even when content is unchanged (checksumFromPreviousCheckWasTheSame path)""" + set_original_response(datastore_path=datastore_path) + + uuid = client.application.config.get('DATASTORE').add_watch(url=url_for('test_endpoint', _external=True)) + + # First check - establishes baseline checksum + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) + wait_for_all_checks(client) + + # Inject a stale last_error directly (simulates a prior failed check) + datastore = client.application.config.get('DATASTORE') + datastore.update_watch(uuid=uuid, update_obj={'last_error': 'Some previous error'}) + assert datastore.data['watching'][uuid].get('last_error') == 'Some previous error' + + # Second check - same content, so checksumFromPreviousCheckWasTheSame will fire + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) + wait_for_all_checks(client) + + # last_error must be cleared even though no change was detected + assert datastore.data['watching'][uuid].get('last_error') == False + + delete_all_watches(client) diff --git a/changedetectionio/worker.py b/changedetectionio/worker.py index 7d04c3eb..41bcd29c 100644 --- a/changedetectionio/worker.py +++ b/changedetectionio/worker.py @@ -284,6 +284,9 @@ async def async_update_worker(worker_id, q, notification_q, app, datastore, exec logger.debug(f'[{uuid}] - checksumFromPreviousCheckWasTheSame - Checksum from previous check was the same, nothing todo here.') # Reset the edited flag since we successfully completed the check watch.reset_watch_edited_flag() + # Page was fetched successfully - clear any previous error state + datastore.update_watch(uuid=uuid, update_obj={'last_error': False}) + cleanup_error_artifacts(uuid, datastore) except content_fetchers_exceptions.BrowserConnectError as e: datastore.update_watch(uuid=uuid,