Skip to content

Commit

Permalink
Compute: result handle additional null case (#12188)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 75d90270fe8f007f3f28cbb8a3dc80e4fffd5a86
  • Loading branch information
tkrause authored and Descartes Labs Build committed Sep 20, 2023
1 parent d629af0 commit aee33e2
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions descarteslabs/core/compute/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ def __init__(
When returned from a compute function, the result will be serialized and stored
in the Storage service with the given attributes.
Notes
-----
Results that are None and have no attributes will not be stored. If you want to
store a None result with attributes, you can do so by passing in a None value
as well as any attributes you wish to set.
Examples
--------
Result with raw binary data:
>>> from descarteslabs.services.compute import ComputeResult
>>> result = ComputeResult(value=b"result", description="result description")
Null result with attributes:
>>> from descarteslabs.services.compute import ComputeResult
>>> result = ComputeResult(None, geometry=geometry, tags=["tag1", "tag2"])
Parameters
----------
value: bytes, Serializable, or Any
Expand All @@ -74,6 +90,17 @@ def __init__(
"""
type_ = type(value)

# The result is null and should not be stored if all attributes are null
# otherwise, we'll allow a user to store a null result with attributes.
self.isnull = (
value is None
and description is None
and expires is None
and extra_properties is None
and geometry is None
and tags is None
)

# If the result is already bytes
if isinstance(value, bytes):
value = value
Expand Down

0 comments on commit aee33e2

Please sign in to comment.