Restock & Price detection - Fix decimal-comma prices ("39,99") being read as 3999 - #4494
Open
jaime-king wants to merge 1 commit into
Open
jaime-king wants to merge 1 commit into
jaime-king wants to merge 1 commit into
Conversation
…read as 3999 (dgtlmoon#4493) The extractors stripped everything but [\d.] before converting, so the decimal comma was thrown away before Restock.parse_currency(), which already understands it, ever saw the value. Route the values through parse_currency() instead, and teach it that a lone "1,299" is a thousands separator so that case does not regress. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4493
Root cause
Restock.parse_currency()(processors/restock_diff/__init__.py:19) already normalises both separator styles:"39,99"→39.99,"1.299,00"→1299.0,"1,299.00"→1299.0. But the extractors never let it see the original value. Each one strips everything except[\d.]first and callsfloat()directly:processors/restock_diff/processor.py:50and:54, in_deduplicate_prices()(extruct path, microdata and JSON-LD)processors/restock_diff/pure_python_extractor.py:244, the JSON-LD string fallback inquery_price_availability()processors/restock_diff/pure_python_extractor.py:138, the microdata text-node pathSo a decimal comma is deleted before parsing:
"39,99"→"3999"→3999.0. Detection still fires because every price is off by the same factor. But the stored price, the watch overview,{{restock.price}}/{{restock.previous_price}}in notifications, and the absoluteprice_change_min/price_change_maxlimits are all 100× too high for any shop that writes prices this way. That's normal for EUR, e.g. every EUR-region Steam store page (example in #4493).The fix
Route all four sites through
Restock().parse_currency()instead offloat(re.sub(...)). Values it can't parse are skipped rather than added asNone.Routing through
parse_currency()would change one case that the old strip-first code handled correctly by accident: a value with only thousands commas, e.g."1,299".parse_currency()reads a lone comma as a decimal separator, which would give1.299. Soparse_currency()now treats commas followed by exact three-digit groups (\d{1,3}(,\d{3})+) as thousands separators, and"1,299"stays1299.0.Source change: +14 / −8 across the three files; the rest is the test.
How I verified
Run inside the published
dgtlmoon/changedetection.io:0.60.7image, with this branch (based ond789fe3) copied in:tests/unit/test_restock_logic.py::TestDiffBuilder::test_price_decimal_commacovers39,99,12.56,1.299,00,1,299.00,1,299,€ 39,99,$159and159. Each goes throughparse_currency(), extruct microdata, extruct JSON-LD, pure-Python JSON-LD, and pure-Python microdata text.master, the new test fails (AssertionError: microdata '39,99'). With the fix it passes.tests/test_restock_itemprop.py tests/test_automatic_follow_ldjson_price.py tests/test_notification_restock_token.py tests/unit/test_restock_logic.py tests/unit/test_restock_deal_filter.py: 22 passed, no failures.3999.0for acontent="39,99"price. A bol.com watch (JSON-LD"price":"12.56") records12.56and is unaffected.What I did not run: the full
run_basic_tests.sh/ browser-fetcher suites. The change is confined to price parsing inrestock_diff, and the CI run on this PR covers the rest.Known limitations (unchanged by this PR)
These are genuinely ambiguous without knowing the page's locale; both behave exactly as on
mastertoday:"1.299") is read as1.299."0,299","12,500") is read as thousands (299,12500).Disclosure: the change, its test and this description were prepared with an AI agent (Claude Code).
🤖 Generated with Claude Code