Skip to content

Commit ad500e6

Browse files
CyberKatzeJenkins
authored andcommitted
livestatus-client: accept typed Query objects in the connection API
The typed `cmk.livestatus_client.queries.Query` could not be passed to the low-level connection methods (`query`, `query_row`, ...): `QueryTypes` only covered `str | livestatus.Query`, so callers had to wrap it in `livestatus.Query(query)` first. Add the existing `_SupportsJsonFormat` protocol to `QueryTypes`. The typed `Query` already satisfies it (it provides `__str__` and `supports_json_format`), so it can now be handed directly to any connection method, which normalizes it internally while preserving the query's output format decision (blob columns stay on the Python format). This avoids a layer-inverting import of the high-level query builder into the low-level connection module. Use this in PredictionQuerier._query_prediction_files, dropping the `livestatus.Query` wrapper. CMK-32809 Change-Id: I081257087671400be61e271650d73b64ead7c55b
1 parent 51f9869 commit ad500e6

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

cmk/utils/prediction/_query.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from cmk.agent_based.prediction_backend import PredictionInfo
1111
from cmk.ccc.hostaddress import HostName
12-
from cmk.livestatus_client import Query as OldQuery
1312
from cmk.livestatus_client import SingleSiteConnection
1413
from cmk.livestatus_client.expressions import And, LqSafe
1514
from cmk.livestatus_client.queries import Query
@@ -56,7 +55,7 @@ def _query_prediction_files(self) -> Iterator[Path]:
5655
)
5756
yield from (
5857
Path(prediction_file)
59-
for prediction_file in self.livestatus_connection.query_row(OldQuery(query))[0]
58+
for prediction_file in self.livestatus_connection.query_row(query)[0]
6059
)
6160

6261
def _query_prediction_file_content(self, relative_file_path: Path) -> bytes:

packages/cmk-livestatus-client/cmk/livestatus_client/_connection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,11 @@ def supports_json_format(self) -> bool:
525525
return self._query.supports_json_format()
526526

527527

528-
QueryTypes = str | Query
528+
# `_SupportsJsonFormat` lets high-level query builders (e.g. the typed
529+
# `cmk.livestatus_client.queries.Query`) be passed directly to the connection
530+
# without this low-level module importing them (which would invert the layer
531+
# dependency). `query`/`query_row`/... normalize such objects into a `Query`.
532+
QueryTypes = str | Query | _SupportsJsonFormat
529533
OnlySites = list[SiteId] | None
530534
DeadSite = dict[str, str | int | Exception | SiteConfiguration]
531535

0 commit comments

Comments
 (0)