From 8fed857b3974eb082ea1a563bac3a421c2d58f26 Mon Sep 17 00:00:00 2001 From: Sankalp Sanand Date: Wed, 13 Dec 2023 13:48:59 -0500 Subject: [PATCH] minor fixes to result attributes --- covalent/_serialize/common.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/covalent/_serialize/common.py b/covalent/_serialize/common.py index 341e112f0..8a633c898 100644 --- a/covalent/_serialize/common.py +++ b/covalent/_serialize/common.py @@ -97,7 +97,10 @@ def deserialize_asset(data: bytes, data_type: AssetType) -> Any: elif data_type == AssetType.JSONABLE: return json.loads(data.decode("utf-8")) elif data_type == AssetType.TEXT: - return data.decode("utf-8") + try: + return data.decode("utf-8") + except UnicodeDecodeError: + return cloudpickle.loads(data) elif data_type == AssetType.BYTES: return data else: @@ -170,6 +173,9 @@ def load_asset(asset_meta: AssetSchema, data_type: AssetType) -> Any: path = uri[len(scheme_prefix) :] if uri.startswith(scheme_prefix) else uri - with open(path, "rb") as f: - data = f.read() + try: + with open(path, "rb") as f: + data = f.read() + except FileNotFoundError: + data = "".encode("utf-8") return deserialize_asset(data, data_type)