Track FlexMeasures server version via response header#193
Conversation
Agent-Logs-Url: https://github.com/FlexMeasures/flexmeasures-client/sessions/db938095-bd2f-4ec5-adea-272655b62c04 Co-authored-by: BelhsanHmida <149331360+BelhsanHmida@users.noreply.github.com>
BelhsanHmida
left a comment
There was a problem hiding this comment.
I reviewed this PR and it looks good to me.
The implementation matches the issue well: server_version is now refreshed from the FlexMeasures-Version response header on each request, ensure_minimum_server_version() still falls back to get_versions() when needed for older servers, and the version-gated checks in get_assets() and update_asset() no longer force an extra version lookup when the version is unknown.
I also tested it manually with this script:
import asyncio
import logging
from flexmeasures_client.client import FlexMeasuresClient
logging.basicConfig(level=logging.INFO)
async def main():
client = FlexMeasuresClient(
host="localhost:5000",
email="admin@admin.com",
password="admin",
)
print("before any API call:", client.server_version)
try:
await client.get_sensors(parse_json_fields=False)
print("after get_sensors():", client.server_version)
await client.get_assets(parse_json_fields=False)
print("after get_assets():", client.server_version)
await client.ensure_minimum_server_version("0.31.0")
print("after ensure_minimum_server_version():", client.server_version)
finally:
await client.close()
asyncio.run(main())And got:
before any API call: None
after get_sensors(): 0.32.0.dev29+g5dea16893
after get_assets(): 0.32.0.dev29+g5dea16893
after ensure_minimum_server_version(): 0.32.0.dev29+g5dea16893So manual testing confirms that server_version is automatically populated after the first API call and remains available for subsequent version checks.
Flix6x
left a comment
There was a problem hiding this comment.
Thanks for the review. Glad to see this works as intended. Could you still fix the failing pipeline, please?
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Coverage Report for CI Build 24157079248Warning Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes. Warning No base build found for commit Coverage: 96.078%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats
💛 - Coveralls |
done. |
The client previously fetched
server_versiononce viaget_versions(), leaving it stale for the session. FlexMeasures now sends aFlexMeasures-Versionheader with every response, enabling continuous version tracking.Changes
Auto-update
server_versionfrom header:request_once()now reads theFlexMeasures-Versionresponse header after each call and updatesself.server_version. Version changes are logged at INFO level.Remove
ensure_server_version(): No longer needed. The three call sites are updated:ensure_minimum_server_version()now falls back toget_versions()directly whenserver_version is None(backward compat for servers without the header)get_assets()/update_asset()version checks are now guarded withif self.server_version is not None— silently skipped when version is unknown rather than triggering a fetchKeep
get_versions(): Retained for external callers and as the fallback path.