Skip to content

bug: better error message after calling to_doc_list on DocVec #1563

@samsja

Description

@samsja

Context

When calling to_doc_list on a DocVec it destroys (delete) the storage of DocVec and therefore the DocVec is not usable.

Nevertheless we can still have a reference to the DocVec object, if we try to call any method on it it will fail with a weird error message. While it is expected that it fail the error message should clearly explain what is the problem: the DocVec should not be used anymore because its content has been moved to a DocList.

Example to reproduce the problem

from docarray import DocVec
from docarray.documents import ImageDoc


docs = DocVec[ImageDoc](
    [ImageDoc(url='http://url.com/foo.png') for _ in range(10)]
)

docs.to_doc_list()

print(docs)
Traceback (most recent call last):
  File "/home/sami/.config/JetBrains/PyCharmCE2023.1/scratches/scratch_2.py", line 11, in <module>
    print(docs)
  File "/home/sami/Documents/workspace/Jina/docarray2/docarray/docarray/array/any_collections.py", line 38, in __repr__
    return f'<{self.__class__.__name__} (length={len(self)})>'
  File "/home/sami/Documents/workspace/Jina/docarray2/docarray/docarray/array/doc_vec/doc_vec.py", line 507, in __len__
    return len(self._storage)
  File "/home/sami/Documents/workspace/Jina/docarray2/docarray/docarray/array/any_array.py", line 51, in __getattr__
    return super().__getattribute__(item)
AttributeError: 'DocVec[ImageDoc]' object has no attribute '_storage'

Expected results

We should rather yield a more explicit error message

RuntimeError: 'DocVec[ImageDoc] has been destroy and cannot be used anymore. Probably because you call `to_doc_list()` on it'

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions