From 84c3c0ae3c9c19f359c5b03dc655543a53b38600 Mon Sep 17 00:00:00 2001 From: "Stephen C. Pope" Date: Mon, 7 Oct 2024 16:52:52 -0600 Subject: [PATCH] Client: Fix event_filters encoding (#12695) GitOrigin-RevId: 39b54a242219b5d5dc2f53513d980cc745f57f8b --- descarteslabs/core/catalog/attributes.py | 5 +++-- .../core/catalog/tests/test_event_subscription.py | 14 ++------------ 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/descarteslabs/core/catalog/attributes.py b/descarteslabs/core/catalog/attributes.py index 16adb00e..2e8094c8 100644 --- a/descarteslabs/core/catalog/attributes.py +++ b/descarteslabs/core/catalog/attributes.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import json import numbers import re @@ -728,7 +729,7 @@ def serialize(self, value, jsonapi_format=False): if value is None: return value if jsonapi_format: - return value.jsonapi_serialize() + return json.dumps(value.jsonapi_serialize()) else: return value.serialize() @@ -753,7 +754,7 @@ def deserialize(self, value, validate=True): return value else: try: - return Expression.parse(value) + return Expression.parse(json.loads(value)) except Exception as ex: raise AttributeValidationError(ex) diff --git a/descarteslabs/core/catalog/tests/test_event_subscription.py b/descarteslabs/core/catalog/tests/test_event_subscription.py index 1b25ad52..d2fa8767 100644 --- a/descarteslabs/core/catalog/tests/test_event_subscription.py +++ b/descarteslabs/core/catalog/tests/test_event_subscription.py @@ -160,12 +160,7 @@ def test_get(self): "created": "2023-09-29T15:54:37.006769Z", "description": "a generic description", "event_filters": [ - { - "and": [ - {"name": "cloud_fraction", "op": "gt", "val": 0.5}, - {"name": "cloud_fraction", "op": "lt", "val": 0.9}, - ] - } + '{"and": [{"name": "cloud_fraction", "op": "gt", "val": 0.5}, {"name": "cloud_fraction", "op": "lt", "val": 0.9}]}', # noqa: E501 ], "event_namespace": ["some-product-id"], "event_source": ["metadata"], @@ -233,12 +228,7 @@ def test_get_unknown_attribute(self): "created": "2023-09-29T15:54:37.006769Z", "description": "a generic description", "event_filters": [ - { - "and": [ - {"name": "cloud_fraction", "op": "gt", "val": 0.5}, - {"name": "cloud_fraction", "op": "lt", "val": 0.9}, - ] - } + '{"and": [{"name": "cloud_fraction", "op": "gt", "val": 0.5}, {"name": "cloud_fraction", "op": "lt", "val": 0.9}]}', # noqa: E501 ], "event_namespace": ["some-product-id"], "event_source": ["metadata"],