codeocean / codeocean-sdk-python

Code Ocean Python SDK
MIT License
3 stars 1 forks source link

error searching for data assets #9

Open dyf opened 1 month ago

dyf commented 1 month ago

I am searching through my data assets in chunks. I find that certain chunks raise a decoding error. Certain offsets work and others do not, unrelated to the size of the offset.

CO deployment: 2.21.4 SDK: 1.1.4.

Here is one that fails:

co_client = CodeOcean(domain="xyz", token="xyz")
query = DataAssetSearchParams(
    limit=100,
    offset=1600,
    archived=False,
    favorite=False
)
query_results = co_client.data_assets.search_data_assets(query)

Stack trace:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[24], line 7
      1 query = DataAssetSearchParams(
      2     limit=100,
      3     offset=1600,
      4     archived=False,
      5     favorite=False
      6 )
----> 7 query_results = co_client.data_assets.search_data_assets(query)

File /opt/conda/lib/python3.9/site-packages/codeocean/data_asset.py:270, in DataAssets.search_data_assets(self, search_params)
    267 def search_data_assets(self, search_params: DataAssetSearchParams) -> DataAssetSearchResults:
    268     res = self.client.post("data_assets/search", json=search_params.to_dict())
--> 270     return DataAssetSearchResults.from_dict(res.json())

File /opt/conda/lib/python3.9/site-packages/dataclasses_json/api.py:70, in DataClassJsonMixin.from_dict(cls, kvs, infer_missing)
     65 @classmethod
     66 def from_dict(cls: Type[A],
     67               kvs: Json,
     68               *,
     69               infer_missing=False) -> A:
---> 70     return _decode_dataclass(cls, kvs, infer_missing)

File /opt/conda/lib/python3.9/site-packages/dataclasses_json/core.py:233, in _decode_dataclass(cls, kvs, infer_missing)
    231     init_kwargs[field.name] = value
    232 elif _is_supported_generic(field_type) and field_type != str:
--> 233     init_kwargs[field.name] = _decode_generic(field_type,
    234                                               field_value,
    235                                               infer_missing)
    236 else:
    237     init_kwargs[field.name] = _support_extended_types(field_type,
    238                                                       field_value)

File /opt/conda/lib/python3.9/site-packages/dataclasses_json/core.py:315, in _decode_generic(type_, value, infer_missing)
    313     xs = dict(zip(_decode_items(_get_type_arg_param(type_, 0), value.keys(), infer_missing), value.values()))
    314 else:
--> 315     xs = _decode_items(_get_type_arg_param(type_, 0), value, infer_missing)
    317 collection_type = _resolve_collection_type_to_decode_to(type_)
    318 res = collection_type(xs)

File /opt/conda/lib/python3.9/site-packages/dataclasses_json/core.py:410, in _decode_items(type_args, xs, infer_missing)
    405     else:
    406         raise TypeError(f"Number of types specified in the collection type {str(type_args)} "
    407                         f"does not match number of elements in the collection. In case you are working with tuples"
    408                         f"take a look at this document "
    409                         f"docs.python.org/3/library/typing.html#annotating-tuples.")
--> 410 return list(_decode_type(type_args, x, infer_missing) for x in xs)

File /opt/conda/lib/python3.9/site-packages/dataclasses_json/core.py:410, in <genexpr>(.0)
    405     else:
    406         raise TypeError(f"Number of types specified in the collection type {str(type_args)} "
    407                         f"does not match number of elements in the collection. In case you are working with tuples"
    408                         f"take a look at this document "
    409                         f"docs.python.org/3/library/typing.html#annotating-tuples.")
--> 410 return list(_decode_type(type_args, x, infer_missing) for x in xs)

File /opt/conda/lib/python3.9/site-packages/dataclasses_json/core.py:247, in _decode_type(type_, value, infer_missing)
    245     return _get_decoder_in_global_config(type_)(value)
    246 if _is_supported_generic(type_):
--> 247     return _decode_generic(type_, value, infer_missing)
    248 if is_dataclass(type_) or is_dataclass(value):
    249     return _decode_dataclass(type_, value, infer_missing)

File /opt/conda/lib/python3.9/site-packages/dataclasses_json/core.py:321, in _decode_generic(type_, value, infer_missing)
    319 elif _is_generic_dataclass(type_):
    320     origin = _get_type_origin(type_)
--> 321     res = _decode_dataclass(origin, value, infer_missing)
    322 else:  # Optional or Union
    323     _args = _get_type_args(type_)

File /opt/conda/lib/python3.9/site-packages/dataclasses_json/core.py:233, in _decode_dataclass(cls, kvs, infer_missing)
    231     init_kwargs[field.name] = value
    232 elif _is_supported_generic(field_type) and field_type != str:
--> 233     init_kwargs[field.name] = _decode_generic(field_type,
    234                                               field_value,
    235                                               infer_missing)
    236 else:
    237     init_kwargs[field.name] = _support_extended_types(field_type,
    238                                                       field_value)

File /opt/conda/lib/python3.9/site-packages/dataclasses_json/core.py:329, in _decode_generic(type_, value, infer_missing)
    327 elif _is_optional(type_) and len(_args) == 2:  # Optional
    328     type_arg = _get_type_arg_param(type_, 0)
--> 329     res = _decode_type(type_arg, value, infer_missing)
    330 else:  # Union (already decoded or try to decode a dataclass)
    331     type_options = _get_type_args(type_)

File /opt/conda/lib/python3.9/site-packages/dataclasses_json/core.py:247, in _decode_type(type_, value, infer_missing)
    245     return _get_decoder_in_global_config(type_)(value)
    246 if _is_supported_generic(type_):
--> 247     return _decode_generic(type_, value, infer_missing)
    248 if is_dataclass(type_) or is_dataclass(value):
    249     return _decode_dataclass(type_, value, infer_missing)

File /opt/conda/lib/python3.9/site-packages/dataclasses_json/core.py:321, in _decode_generic(type_, value, infer_missing)
    319 elif _is_generic_dataclass(type_):
    320     origin = _get_type_origin(type_)
--> 321     res = _decode_dataclass(origin, value, infer_missing)
    322 else:  # Optional or Union
    323     _args = _get_type_args(type_)

File /opt/conda/lib/python3.9/site-packages/dataclasses_json/core.py:185, in _decode_dataclass(cls, kvs, infer_missing)
    182 if not field.init:
    183     continue
--> 185 field_value = kvs[field.name]
    186 field_type = types[field.name]
    187 if field_value is None:

KeyError: 'data_assets'
Iain-CO commented 1 month ago

Thank you for reporting this @dyf , we're taking a look and will keep you updated.