From aee33e29c0273e8607eb79c5616e8efea96286ca Mon Sep 17 00:00:00 2001 From: Tom Krause Date: Wed, 20 Sep 2023 09:23:04 -0600 Subject: [PATCH] Compute: result handle additional null case (#12188) GitOrigin-RevId: 75d90270fe8f007f3f28cbb8a3dc80e4fffd5a86 --- descarteslabs/core/compute/result.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/descarteslabs/core/compute/result.py b/descarteslabs/core/compute/result.py index 21b59fba..095fffda 100644 --- a/descarteslabs/core/compute/result.py +++ b/descarteslabs/core/compute/result.py @@ -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 @@ -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