Skip to content
This repository was archived by the owner on Sep 9, 2026. It is now read-only.
This repository was archived by the owner on Sep 9, 2026. It is now read-only.

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

Closed

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'

Activity

  1. moved this to Todo/Bug in DocArray backlogon May 23, 2023
  2. changed the title [-]feat: better error message after calling `to_doc_list` on DocVec[/-] [+]bug: better error message after calling `to_doc_list` on DocVec[/+] on May 23, 2023
  3. moved this from Todo/Bug to In Progress in DocArray backlogon Jun 27, 2023
  4. moved this from In Progress to Done in DocArray backlogon Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions