From dd5f2ba5e4f0f46eb3da487ade4d4dd5fb9fcab6 Mon Sep 17 00:00:00 2001 From: Jens Bergmann <1742418+1cu@users.noreply.github.com> Date: Sun, 9 Feb 2025 03:14:19 +0100 Subject: [PATCH] fix: Ensure Consistent Content Hash Calculation (#415) This commit addresses an issue where the content hash was being calculated on the current configuration (`ad_cfg`) instead of the original configuration (`ad_cfg_orig`). This could lead to inconsistent hash values, especially when the configuration is updated during the execution of the program. The fix involves calculating the content hash on the original configuration (`ad_cfg_orig`) in both the `__check_ad_republication` and `publish_ad` methods. This ensures that the hash value is consistent and matches what was stored. The relevant code changes are as follows: - In the `__check_ad_republication` method, the content hash is now calculated on `ad_cfg_orig` instead of `ad_cfg`. - In the `publish_ad` method, the content hash is also calculated on `ad_cfg_orig` to ensure consistency. These changes should improve the reliability of the content hash comparison and the overall stability of the application. --- src/kleinanzeigen_bot/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/kleinanzeigen_bot/__init__.py b/src/kleinanzeigen_bot/__init__.py index 0a0653e..0037c8d 100644 --- a/src/kleinanzeigen_bot/__init__.py +++ b/src/kleinanzeigen_bot/__init__.py @@ -279,7 +279,8 @@ class KleinanzeigenBot(WebScrapingMixin): # Check for changes first if ad_cfg["id"]: - current_hash = calculate_content_hash(ad_cfg) + # Calculate hash on original config to match what was stored + current_hash = calculate_content_hash(ad_cfg_orig) stored_hash = ad_cfg_orig.get("content_hash") LOG.debug("Hash comparison for [%s]:", ad_file_relative) @@ -787,7 +788,8 @@ class KleinanzeigenBot(WebScrapingMixin): ad_cfg_orig["id"] = ad_id # Update content hash after successful publication - ad_cfg_orig["content_hash"] = calculate_content_hash(ad_cfg) + # Calculate hash on original config to ensure consistent comparison on restart + ad_cfg_orig["content_hash"] = calculate_content_hash(ad_cfg_orig) ad_cfg_orig["updated_on"] = datetime.utcnow().isoformat() if not ad_cfg["created_on"] and not ad_cfg["id"]: ad_cfg_orig["created_on"] = ad_cfg_orig["updated_on"]