Minimal example:
import strawberry
from pydantic import BaseModel
from typing import Literal
class Model(BaseModel):
name: Literal["test"]
@strawberry.experimental.pydantic.type(model=Model, all_fields=True)
class BerryModel:
"""Oh no"""
throws
/usr/local/lib/python3.8/site-packages/strawberry/experimental/pydantic/object_type.py:102: in wrap
all_model_fields: List[Tuple[str, Any, dataclasses.Field]] = [
/usr/local/lib/python3.8/site-packages/strawberry/experimental/pydantic/object_type.py:105: in <listcomp>
get_type_for_field(field),
/usr/local/lib/python3.8/site-packages/strawberry/experimental/pydantic/object_type.py:56: in get_type_for_field
type_ = replace_pydantic_types(type_)
/usr/local/lib/python3.8/site-packages/strawberry/experimental/pydantic/object_type.py:29: in replace_pydantic_types
tuple(replace_pydantic_types(t) for t in type_.__args__)
/usr/local/lib/python3.8/site-packages/strawberry/experimental/pydantic/object_type.py:29: in <genexpr>
tuple(replace_pydantic_types(t) for t in type_.__args__)
/usr/local/lib/python3.8/site-packages/strawberry/experimental/pydantic/object_type.py:44: in replace_pydantic_types
if issubclass(type_, BaseModel):
/usr/local/lib/python3.8/abc.py:102: in __subclasscheck__
return _abc_subclasscheck(cls, subclass)
E TypeError: issubclass() arg 1 must be a class
I'm fairly sure this is because the __args__
of Literal are just the strings,
>>> from typing import Literal
>>> name = Literal["name"]
>>> name.__args__
('name',)
because, to continue the example
issubclass("name", BaseModel)
will throw the error above
I will look into a fix - any help from the original author would be appreciated, however :)
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too