Skip to content

Commit

Permalink
Client: Fix event_filters encoding (#12695)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 39b54a242219b5d5dc2f53513d980cc745f57f8b
  • Loading branch information
stephencpope authored and Descartes Labs Build committed Oct 7, 2024
1 parent ea8b4d0 commit 84c3c0a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
5 changes: 3 additions & 2 deletions descarteslabs/core/catalog/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import numbers
import re

Expand Down Expand Up @@ -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()

Expand All @@ -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)

Expand Down
14 changes: 2 additions & 12 deletions descarteslabs/core/catalog/tests/test_event_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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"],
Expand Down

0 comments on commit 84c3c0a

Please sign in to comment.