Skip to content

Commit 694594c

Browse files
cursor[bot]cursoragenthenchaves
authored
feat: send checks as spec instead of deprecated assertions (#86)
--------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Henrique Chaves <henrique@giskard.ai>
1 parent 2f02bbb commit 694594c

11 files changed

Lines changed: 917 additions & 177 deletions

File tree

src/giskard_hub/resources/checks.py

Lines changed: 98 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Any, List, Optional
3+
from typing import Dict, List, Optional
44

55
import httpx
66

@@ -21,6 +21,7 @@
2121
CheckCreateParams,
2222
CheckUpdateParams,
2323
CheckBulkDeleteParams,
24+
_check_param_to_spec,
2425
)
2526
from .._base_client import make_request_options
2627
from ..types.common import APIResponse
@@ -51,10 +52,11 @@ def with_streaming_response(self) -> ChecksResourceWithStreamingResponse:
5152
def create(
5253
self,
5354
*,
54-
params: CheckTypeParam,
5555
identifier: str,
5656
name: str,
5757
project_id: str,
58+
params: CheckTypeParam | Omit = omit,
59+
spec: Dict[str, object] | Omit = omit,
5860
description: Optional[str] | Omit = omit,
5961
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
6062
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -67,14 +69,18 @@ def create(
6769
6870
Parameters
6971
----------
70-
params : CheckTypeParam
71-
Check-specific parameters (e.g. ``{"reference": "..."}`` for correctness).
7272
identifier : str
7373
Unique identifier of the check.
7474
name : str
7575
Display name of the check.
7676
project_id : str
7777
Project ID to create the check in.
78+
params : CheckTypeParam | Omit
79+
Check-specific parameters (e.g. `{"reference": "..."}` for correctness).
80+
Cannot be combined with `spec`.
81+
spec : Dict[str, object] | Omit
82+
Raw check spec with a `kind` discriminator (e.g. `{"kind": "hub_correctness", "reference": "..."}`).
83+
Cannot be combined with `params`.
7884
description : str | None | Omit
7985
Human-readable description of the check.
8086
@@ -93,12 +99,26 @@ def create(
9399
-------
94100
Check
95101
The newly created check.
102+
103+
Raises
104+
------
105+
ValueError
106+
If both `params` and `spec` are provided, or if neither is provided.
96107
"""
108+
params_provided = not isinstance(params, Omit)
109+
spec_provided = not isinstance(spec, Omit)
110+
111+
if params_provided and spec_provided:
112+
raise ValueError("Cannot provide both 'params' and 'spec'. Use 'spec' or 'params' but not both.")
113+
if not params_provided and not spec_provided:
114+
raise ValueError("Must provide either 'params' or 'spec'.")
115+
116+
api_spec = spec if spec_provided else _check_param_to_spec(identifier, params)
97117
response = self._post(
98118
"/v2/checks",
99119
body=maybe_transform(
100120
{
101-
"assertions": [params],
121+
"spec": api_spec,
102122
"description": description,
103123
"identifier": identifier,
104124
"name": name,
@@ -151,7 +171,7 @@ def retrieve(
151171
Raises
152172
------
153173
ValueError
154-
If ``check_id`` is empty.
174+
If `check_id` is empty.
155175
"""
156176
if not check_id:
157177
raise ValueError(f"Expected a non-empty value for `check_id` but received {check_id!r}")
@@ -170,6 +190,7 @@ def update(
170190
check_id: str,
171191
*,
172192
params: Optional[CheckTypeParam] | Omit = omit,
193+
spec: Optional[Dict[str, object]] | Omit = omit,
173194
description: Optional[str] | Omit = omit,
174195
identifier: Optional[str] | Omit = omit,
175196
name: Optional[str] | Omit = omit,
@@ -187,7 +208,9 @@ def update(
187208
check_id : str
188209
ID of the check to update.
189210
params : CheckTypeParam | None | Omit
190-
Updated check-specific parameters.
211+
Updated check-specific parameters. Cannot be combined with `spec`.
212+
spec : Dict[str, object] | None | Omit
213+
Raw check spec with a `kind` discriminator. Cannot be combined with `params`.
191214
description : str | None | Omit
192215
Updated description of the check.
193216
identifier : str | None | Omit
@@ -214,20 +237,33 @@ def update(
214237
Raises
215238
------
216239
ValueError
217-
If ``check_id`` is empty.
240+
If `check_id` is empty, or if both `params` and `spec` are provided.
218241
"""
219242
if not check_id:
220243
raise ValueError(f"Expected a non-empty value for `check_id` but received {check_id!r}")
221-
api_assertions: list[Any] | Omit | None
222-
if params is None or isinstance(params, Omit):
223-
api_assertions = params # type: ignore[assignment]
244+
245+
params_provided = not isinstance(params, Omit)
246+
spec_provided = not isinstance(spec, Omit)
247+
248+
if params_provided and spec_provided:
249+
raise ValueError("Cannot provide both 'params' and 'spec'. Use 'spec' or 'params' but not both.")
250+
251+
api_spec: Dict[str, object] | Omit | None
252+
if spec_provided:
253+
api_spec = spec
254+
elif params_provided:
255+
if params is None:
256+
api_spec = None
257+
else:
258+
type_or_id = identifier if isinstance(identifier, str) else None
259+
api_spec = _check_param_to_spec(type_or_id, params)
224260
else:
225-
api_assertions = [params]
261+
api_spec = omit
226262
response = self._patch(
227263
f"/v2/checks/{check_id}",
228264
body=maybe_transform(
229265
{
230-
"assertions": api_assertions,
266+
"spec": api_spec,
231267
"description": description,
232268
"identifier": identifier,
233269
"name": name,
@@ -331,7 +367,7 @@ def delete(
331367
Raises
332368
------
333369
ValueError
334-
If ``check_id`` is empty.
370+
If `check_id` is empty.
335371
"""
336372
if not check_id:
337373
raise ValueError(f"Expected a non-empty value for `check_id` but received {check_id!r}")
@@ -412,10 +448,11 @@ def with_streaming_response(self) -> AsyncChecksResourceWithStreamingResponse:
412448
async def create(
413449
self,
414450
*,
415-
params: CheckTypeParam,
416451
identifier: str,
417452
name: str,
418453
project_id: str,
454+
params: CheckTypeParam | Omit = omit,
455+
spec: Dict[str, object] | Omit = omit,
419456
description: Optional[str] | Omit = omit,
420457
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
421458
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -428,14 +465,18 @@ async def create(
428465
429466
Parameters
430467
----------
431-
params : CheckTypeParam
432-
Check-specific parameters (e.g. ``{"reference": "..."}`` for correctness).
433468
identifier : str
434469
Unique identifier of the check.
435470
name : str
436471
Display name of the check.
437472
project_id : str
438473
Project ID to create the check in.
474+
params : CheckTypeParam | Omit
475+
Check-specific parameters (e.g. `{"reference": "..."}` for correctness).
476+
Cannot be combined with `spec`.
477+
spec : Dict[str, object] | Omit
478+
Raw check spec with a `kind` discriminator (e.g. `{"kind": "hub_correctness", "reference": "..."}`).
479+
Cannot be combined with `params`.
439480
description : str | None | Omit
440481
Human-readable description of the check.
441482
@@ -454,12 +495,26 @@ async def create(
454495
-------
455496
Check
456497
The newly created check.
498+
499+
Raises
500+
------
501+
ValueError
502+
If both `params` and `spec` are provided, or if neither is provided.
457503
"""
504+
params_provided = not isinstance(params, Omit)
505+
spec_provided = not isinstance(spec, Omit)
506+
507+
if params_provided and spec_provided:
508+
raise ValueError("Cannot provide both 'params' and 'spec'. Use 'spec' or 'params' but not both.")
509+
if not params_provided and not spec_provided:
510+
raise ValueError("Must provide either 'params' or 'spec'.")
511+
512+
api_spec = spec if spec_provided else _check_param_to_spec(identifier, params)
458513
response = await self._post(
459514
"/v2/checks",
460515
body=await async_maybe_transform(
461516
{
462-
"assertions": [params],
517+
"spec": api_spec,
463518
"description": description,
464519
"identifier": identifier,
465520
"name": name,
@@ -512,7 +567,7 @@ async def retrieve(
512567
Raises
513568
------
514569
ValueError
515-
If ``check_id`` is empty.
570+
If `check_id` is empty.
516571
"""
517572
if not check_id:
518573
raise ValueError(f"Expected a non-empty value for `check_id` but received {check_id!r}")
@@ -531,6 +586,7 @@ async def update(
531586
check_id: str,
532587
*,
533588
params: Optional[CheckTypeParam] | Omit = omit,
589+
spec: Optional[Dict[str, object]] | Omit = omit,
534590
description: Optional[str] | Omit = omit,
535591
identifier: Optional[str] | Omit = omit,
536592
name: Optional[str] | Omit = omit,
@@ -548,7 +604,9 @@ async def update(
548604
check_id : str
549605
ID of the check to update.
550606
params : CheckTypeParam | None | Omit
551-
Updated check-specific parameters.
607+
Updated check-specific parameters. Cannot be combined with `spec`.
608+
spec : Dict[str, object] | None | Omit
609+
Raw check spec with a `kind` discriminator. Cannot be combined with `params`.
552610
description : str | None | Omit
553611
Updated description of the check.
554612
identifier : str | None | Omit
@@ -575,20 +633,33 @@ async def update(
575633
Raises
576634
------
577635
ValueError
578-
If ``check_id`` is empty.
636+
If `check_id` is empty, or if both `params` and `spec` are provided.
579637
"""
580638
if not check_id:
581639
raise ValueError(f"Expected a non-empty value for `check_id` but received {check_id!r}")
582-
api_assertions: list[Any] | Omit | None
583-
if params is None or isinstance(params, Omit):
584-
api_assertions = params # type: ignore[assignment]
640+
641+
params_provided = not isinstance(params, Omit)
642+
spec_provided = not isinstance(spec, Omit)
643+
644+
if params_provided and spec_provided:
645+
raise ValueError("Cannot provide both 'params' and 'spec'. Use 'spec' or 'params' but not both.")
646+
647+
api_spec: Dict[str, object] | Omit | None
648+
if spec_provided:
649+
api_spec = spec
650+
elif params_provided:
651+
if params is None:
652+
api_spec = None
653+
else:
654+
type_or_id = identifier if isinstance(identifier, str) else None
655+
api_spec = _check_param_to_spec(type_or_id, params)
585656
else:
586-
api_assertions = [params]
657+
api_spec = omit
587658
response = await self._patch(
588659
f"/v2/checks/{check_id}",
589660
body=await async_maybe_transform(
590661
{
591-
"assertions": api_assertions,
662+
"spec": api_spec,
592663
"description": description,
593664
"identifier": identifier,
594665
"name": name,
@@ -692,7 +763,7 @@ async def delete(
692763
Raises
693764
------
694765
ValueError
695-
If ``check_id`` is empty.
766+
If `check_id` is empty.
696767
"""
697768
if not check_id:
698769
raise ValueError(f"Expected a non-empty value for `check_id` but received {check_id!r}")

0 commit comments

Comments
 (0)