From 0b3b2a1af2744e65192048a744468ee01845aa22 Mon Sep 17 00:00:00 2001 From: Sam Lock Date: Thu, 19 Dec 2024 10:46:26 +0000 Subject: [PATCH] omit check_request params with None values Signed-off-by: Sam Lock --- cerbos/sdk/_async/_http.py | 6 +++++- cerbos/sdk/_sync/_http.py | 6 +++++- cerbos/sdk/model.py | 6 ++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cerbos/sdk/_async/_http.py b/cerbos/sdk/_async/_http.py index 3de54c7..a320c00 100644 --- a/cerbos/sdk/_async/_http.py +++ b/cerbos/sdk/_async/_http.py @@ -196,7 +196,11 @@ async def check_resources( resources=resources.resources, aux_data=aux_data, ) - resp = await self._http.post("/api/check/resources", json=req.to_dict()) + + # omit keys with `None` values + req_params = {k: v for k, v in req.to_dict().items() if v is not None} + + resp = await self._http.post("/api/check/resources", json=req_params) if resp.is_error: if self._raise_on_error: raise CerbosRequestException(APIError.from_dict(resp.json())) diff --git a/cerbos/sdk/_sync/_http.py b/cerbos/sdk/_sync/_http.py index 5b3948a..da8886a 100644 --- a/cerbos/sdk/_sync/_http.py +++ b/cerbos/sdk/_sync/_http.py @@ -196,7 +196,11 @@ def check_resources( resources=resources.resources, aux_data=aux_data, ) - resp = self._http.post("/api/check/resources", json=req.to_dict()) + + # omit keys with `None` values + req_params = {k: v for k, v in req.to_dict().items() if v is not None} + + resp = self._http.post("/api/check/resources", json=req_params) if resp.is_error: if self._raise_on_error: raise CerbosRequestException(APIError.from_dict(resp.json())) diff --git a/cerbos/sdk/model.py b/cerbos/sdk/model.py index db6ff52..2d8211e 100644 --- a/cerbos/sdk/model.py +++ b/cerbos/sdk/model.py @@ -272,7 +272,9 @@ def __init__(self, error: Optional[APIError]): self.error = error -class CerbosTLSError(Exception): ... +class CerbosTLSError(Exception): + ... -class CerbosTypeError(Exception): ... +class CerbosTypeError(Exception): + ...