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 with DocList[] #1782

Closed
Closed

Description

@samsja

Context

from docarray import DocList, BaseDoc

docs = DocList[BaseDoc()]# 1

class MyDoc(BaseDoc):
    text: str

DocList[MyDoc][MyDoc] # 2

Both 1 and 2 lines should failed with a nice error message

description

DocList[X] should only accept BaseDoc class and should not be called twice

How to do it

This should be as easy as adding if else statement and raise properly error in this part of the codebase:

if not safe_issubclass(item, BaseDoc):

Activity

  1. converted this from a draft issue on Sep 13, 2023
  2. punndcoder28 commented on Sep 14, 2023

    @punndcoder28
    Contributor

    Hi @samsja I can work on this. From the docs I understand that the correct way is

    from docarray import DocList, BaseDoc
    
    class MyDoc(BaseDoc):
        text: str
    
    docs = DocList[BaseDoc]([MyDoc])
    
  3. samsja commented on Sep 15, 2023

    @samsja
    MemberAuthor

    Yes exactly, the problem is that if you do DocList[BaseDoc()] it will work but it should not

  4. punndcoder28 commented on Sep 15, 2023

    @punndcoder28
    Contributor

    Understood. Will go through the custom implementation of safe_issubclass method and propose a solution for this issue

  5. JoanFM commented on Sep 15, 2023

    @JoanFM
    Member

    I do not think is that code u have to check, is the specific line, the safe_issubclass method should not be touched I think

  6. punndcoder28 commented on Sep 16, 2023

    @punndcoder28
    Contributor

    Checked the implementation of classes DocList and AnyDocArray and noticed that

    if isinstance(item, type) and safe_issubclass(item, BaseDoc):

    the above line fails when we do

    from docarray import DocList, BaseDoc
    
    doc = DocList[BaseDoc()]
    

    and the control goes to

    return super().__class_getitem__(item)

    but does not end up in the class AnyDocArray so we can handle this case in __class_getitem__ method of DocList by adding a condition to check
    if isinstance(item, object) and raise an exception of type ValueError

  7. JoanFM commented on Sep 16, 2023

    @JoanFM
    Member

    Checked the implementation of classes DocList and AnyDocArray and noticed that

    if isinstance(item, type) and safe_issubclass(item, BaseDoc):

    the above line fails when we do

    from docarray import DocList, BaseDoc
    
    doc = DocList[BaseDoc()]
    

    and the control goes to

    return super().__class_getitem__(item)

    but does not end up in the class AnyDocArray so we can handle this case in __class_getitem__ method of DocList by adding a condition to check
    if isinstance(item, object) and raise an exception of type ValueError

    sounds reasonable

  8. JoanFM commented on Sep 19, 2023

    @JoanFM
    Member

    The second part of the ticket remains valid, will open a new issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions