#TypeError: issubclass() arg 1 must be a class

1 messages · Page 1 of 1 (latest)

mental wraith
#

Hi All, I am getting the below error while trying to run my dagger method via dagger call

TypeError: issubclass() arg 1 must be a class

This is raised from inside dagger -

/dagger/mod/_converter.py:107 in │ to_typedef │ │ 104 │ if typ.hint in builtins: │ 105 │ return td.with_kind(builtins[typ.hint]) │ 106 │ │ ❱ 107 │ if issubclass(cls := typ.hint, enum.Enum): │ 108 │ return td.with_enum(cls.__name__, description=get_doc(cls))

Any clue on what might be the cause? I can provide more info if needed.

fading brook
#

Hmm, potentially related to enums? Not an answer but have you managed to compare your function/method to one of the existing examples? Maybe you have a bit of misconfiguration? I'd check out something like https://docs.dagger.io/api/enumerations and go on the Python tab

Dagger supports custom enumeration (enum) types, which can be used to restrict possible values for a string argument. Enum values are strictly validated, preventing common mistakes like accidentally passing null, true, or false.

halcyon flower
broken estuary
#

The error implies that there's a wrong type annotation somewhere, like on a function argument or return type. The previous call in the stack trace should clarify which. In any case, that error message can be improved, just need to reproduce it.

mental wraith
#

I do think it was related to a function argument or return type, I did try by deduction to point out the issue and could come to this method. There was no dagger related operation happening within this so ultimately decided to have this as a normal python code (without @function and @object_type on the class) I am not able to provide any code that can be used to reproduce this issue due to IP concerns.

But here is the piece of code I think is responsible and the stack trace as well.

@function
def cleanup_after_tests(
        self,
        base_url: str,
        admin_jwt: str,
        product_name: str,
        created_endpoint_ids: List[int]
) -> None:
    """
    1) Unlinks endpoints (i.e., sets linked_endpoint_ids=[]) using /admin/product/{product_name}.
    2) Deletes the endpoints themselves.
    """

    # 1) Unlink endpoints from the product
    #    We pass an empty list of endpoints, so they're all removed.
    Service1().update_product(
        base_url=base_url,
        admin_jwt=admin_jwt,
        product_name=product_name,
        linked_endpoint_ids=[],
        roles_admin=False
    )
    print(f"Unlinked endpoints from product '{product_name}'.")

    # 2) Delete endpoints
    for endpoint_id in created_endpoint_ids:
        if endpoint_id is not None:
            Service1().delete_endpoint(base_url, admin_jwt, endpoint_id)
            print(f"Deleted endpoint with ID={endpoint_id}")
        else:
            print("Skipping endpoint without ID.")

stack trace is attached.

broken estuary
mental wraith
#

I had this when the error occured -

from typing import List, Any, Dict

import requests
from dagger import object_type, function, field

@object_type
class Roles:
admin: bool = field(default=False)

@object_type
class EndpointData:
id: int = field()
url: str = field()
# More similar fields

@object_type
class ProductData:
name: str = field()
roles: Roles = field(default=False)
linked_endpoint_ids: List[int] = field(default=list)

These being returned by some functions

@object_type
class MyClass:
@function
def some_function() -> ProductData:
....more such methods.

#

After moving away from dagger annotations for all this code the problem was solved but I couldn't understand what really caused it.

broken estuary
#

Btw, for lists, just define them with list, like:

ids: list[int]

Don't use List which is deprecated since Python 3.9.

#

Same with Dict, etc.

broken estuary
# mental wraith After moving away from dagger annotations for all this code the problem was solv...

Oh, reading this again I realize the problem still exists in the code you showed. You were just saying that it's fixed without the dagger annotations. If so, then I think it's that List:

>>> from typing import List
> issubclass(List, list)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: issubclass() arg 1 must be a class

List should work in Dagger, even if not recommended. I remember having an issue to fix this. Need to look for it.