Conversation
…overlap The REST tariff endpoints return a DIRECT_DEBIT row and a NON_DIRECT_DEBIT row over the same validity window. Both went unfiltered into minute_data(), which writes each row over its range, so the row appearing last in the response won. Measured against the live public API for E-1R-VAR-22-11-01-A: predbat used 27.8488 where the direct debit rate is 26.381355, and 5 of the 17 windows returned put DIRECT_DEBIT last, so the displayed variant was not even stable between periods. filter_payment_method() now runs at both parse points, the OctopusAPI component path and the legacy import_octopus_url path. Rows with payment_method None (Agile, day/night), rows without the key, and responses that never mention DIRECT_DEBIT are all left untouched. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Closes #5144
The bug
The REST tariff endpoints return two overlapping rows per validity window, one
DIRECT_DEBITand oneNON_DIRECT_DEBIT. Both go straight intominute_data(), which writes each row over its range, so whichever row comes last in the response wins.Reproduced against the live public API (
E-1R-VAR-22-11-01-A, no auth), using the repository's ownminute_data:So a direct debit customer is shown the higher rate — and the last line is the part that is easy to miss: 5 of the 17 windows the API returns put
DIRECT_DEBITlast, so the displayed rate silently flips variant from one period to the next rather than always being the higher one.payment_methodappeared nowhere in the production code before this change — only in test fixtures.The fix
A module-level
filter_payment_method()inoctopus.py, applied at both parse points, as suggested in the triage on the issue:get_octopus_rates_direct()— the OctopusAPI component path, for unit rates and standing charges;download_octopus_rates_func()— the legacyimport_octopus_url/ compare path.It is deliberately conservative:
payment_method: None(Agile, day/night) pass through untouched;DIRECT_DEBITis returned unchanged, so a non-direct-debit-only feed keeps its rate rather than becoming empty.Filtering at the parse point rather than at download also covers data already sitting in the URL and storage caches.
Tests
A seventh sub-test in
tests/test_octopus_url.py(payment_method), covering the five cases:payment_method: NoneNON_DIRECT_DEBITrowsRun with the fix:
RESULTS: 7 passed, 0 failed out of 7 tests.Run with
octopus.pyreverted tomain, to show the test would have caught this:Note that the "direct debit row last" case passes even without the fix — that is the order-dependence itself.
Other checks
./run_all --quick: the only failure ispredheat("Predheat did not run promptly after being re-enabled"), which fails the same way on a clean checkout ofmainon this machine (Windows), so it is unrelated to this change.black --checkon both files: unchanged.flake8: same number of findings asmainonoctopus.py(all pre-existing).interrogate: 90.4% onmain→ 90.6% with this change, for these two files.🤖 Generated with Claude Code