Skip to content

Track FlexMeasures server version via response header#193

Merged
Flix6x merged 3 commits intomainfrom
copilot/update-server-version-tracking
Apr 8, 2026
Merged

Track FlexMeasures server version via response header#193
Flix6x merged 3 commits intomainfrom
copilot/update-server-version-tracking

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 31, 2026

The client previously fetched server_version once via get_versions(), leaving it stale for the session. FlexMeasures now sends a FlexMeasures-Version header with every response, enabling continuous version tracking.

Changes

  • Auto-update server_version from header: request_once() now reads the FlexMeasures-Version response header after each call and updates self.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 to get_versions() directly when server_version is None (backward compat for servers without the header)
    • get_assets() / update_asset() version checks are now guarded with if self.server_version is not None — silently skipped when version is unknown rather than triggering a fetch
  • Keep get_versions(): Retained for external callers and as the fallback path.

# After any API call, server_version is automatically populated:
await client.get_sensors()
print(client.server_version)  # e.g. "0.32.0"

# If version changes mid-session, it's logged:
# INFO: FlexMeasures server version changed from 0.32.0 to 0.33.0.

# ensure_minimum_server_version() still works when server_version is None
# (older server) — it calls get_versions() as fallback:
await client.ensure_minimum_server_version("0.31.0")

Copilot AI changed the title [WIP] Update server version tracking via header Track FlexMeasures server version via response header Mar 31, 2026
Copilot AI requested a review from BelhsanHmida March 31, 2026 15:26
@BelhsanHmida BelhsanHmida marked this pull request as ready for review April 6, 2026 11:13
Copy link
Copy Markdown
Contributor

@BelhsanHmida BelhsanHmida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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+g5dea16893

So manual testing confirms that server_version is automatically populated after the first API call and remains available for subsequent version checks.

@BelhsanHmida BelhsanHmida requested a review from Flix6x April 6, 2026 11:18
Copy link
Copy Markdown
Contributor

@Flix6x Flix6x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@coveralls
Copy link
Copy Markdown

Coverage Report for CI Build 24157079248

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Warning

No base build found for commit 7866f1b on main.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 96.078%

Details

  • Patch coverage: 10 of 10 lines across 1 file are fully covered (100%).

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 663
Covered Lines: 637
Line Coverage: 96.08%
Coverage Strength: 5.76 hits per line

💛 - Coveralls

@BelhsanHmida
Copy link
Copy Markdown
Contributor

Copilot uses AI. Check for mistakes.

Sorry, something went wrong.

done.

Copy link
Copy Markdown
Contributor

@Flix6x Flix6x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@Flix6x Flix6x merged commit 54d843b into main Apr 8, 2026
10 checks passed
@Flix6x Flix6x deleted the copilot/update-server-version-tracking branch April 8, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep track of FlexMeasures version via header

4 participants