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.
This commit is contained in:
Jens Bergmann
2025-02-09 03:14:19 +01:00
committed by GitHub
parent 042525eb91
commit dd5f2ba5e4

View File

@@ -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"]