Send the client version in a FlexMeasures-Client-Version request header - #226
Merged
Merged
Conversation
…t header Every request now carries the client version, including the unauthenticated token and versions requests and file uploads, so the server knows it from the very first request. The name mirrors the server's FlexMeasures-Version response header. This lets a FlexMeasures server adapt responses to what a client supports, instead of relying on a manually set asset attribute. Existing tests that assert the exact request headers now expect the new header. Closes #212 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019heS4SVj8UqZ8BiMqDvoXj Signed-off-by: F.N. Claessen <claessen@seita.nl>
Coverage Report for CI Build 35134394770Coverage increased (+0.007%) to 96.831%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
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 #212
Why
A FlexMeasures server can't tell which client version is calling it.
When the server changes a response in a way older clients misread, the only way to protect those clients is manual. The host sets
FLEXMEASURES_LEGACY_JOB_RESPONSES_MAX_INCOMPATIBLE_CLIENT_VERSIONand adds a version attribute to each affected asset.A recent case: FlexMeasures ≥ v1.0.0 returns 202 while a scheduling job runs, and client 0.9.3 read that as the finished schedule. The Home Assistant integration then failed with
KeyError: 'values'(see FlexMeasures/flexmeasures-ha-integration#31).With the version in every request, the server can make that decision per request, with no attributes to set.
What
FlexMeasures-Client-Version: <flexmeasures_client.__version__>. It's added inget_headers(), so it covers:requestAuthToken,get_versions), so the server knows the version from the first request;Content-Typefrom those headers.constants.CLIENT_VERSION_HEADER.Why a custom header rather than
User-AgentFlexMeasures-Versionresponse header.User-Agentbelongs to the calling app. Home Assistant's shared session already sets it toHomeAssistant/… aiohttp/… Python/…. Overwriting that would hide the app from server logs, and merging our token in would mean editing a header the client doesn't own.User-Agentlist.Adding a
flexmeasures-client/<version>token toUser-Agentfor logs and proxies could be a separate change.Tests
test_every_request_sends_the_client_version: runs a token request, a versions request, an authenticated GET and a file upload, and checks that all four send the header.get_headers(), 17 tests fail, including the new one. With it restored, the whole non-S2 suite passes (224 tests).Follow-up on the FlexMeasures side (not in this PR)
use_legacy_job_responses()could read this header before checking asset attributes.🤖 Generated with Claude Code
https://claude.ai/code/session_019heS4SVj8UqZ8BiMqDvoXj