Open invokermain opened 2 years ago
Using a field resolver with return type of list or List (as opposed to say list[int] etc) raising an internal exception:
list
List
list[int]
AttributeError: __args__. Did you mean: '__ror__'?
This is due to the lack of a len check when calling evaled_type.__args__[0] in this function:
evaled_type.__args__[0]
class StrawberryAnnotation: ... # skipped code def create_list(self, evaled_type: Any) -> StrawberryList: of_type = StrawberryAnnotation( annotation=evaled_type.__args__[0], namespace=self.namespace, ).resolve() return StrawberryList(of_type
I am not sure what the desired behaviour is, maybe either:
list[Any]
Example Code:
from typing import List import strawberry @strawberry.type class MyItemType: my_field: int def typing_list_resolver() -> List: return [MyItemType(2), MyItemType(3)] def builtin_list_resolver() -> list: return [MyItemType(2), MyItemType(3)] @strawberry.type class Query: my_item: List[MyItemType] = strawberry.field(typing_list_resolver) @strawberry.type class Query2: my_item: list[MyItemType] = strawberry.field(builtin_list_resolver) if __name__ == "__main__": # raises `AttributeError: __args__. Did you mean: '__ror__'?` strawberry.Schema(Query) # raises `AttributeError: __args__. Did you mean: '__ror__'?` strawberry.Schema(Query2)
we should provide a better error, I don't think we should treat it as list[Any] 😊
Describe the Bug
Using a field resolver with return type of
list
orList
(as opposed to saylist[int]
etc) raising an internal exception:This is due to the lack of a len check when calling
evaled_type.__args__[0]
in this function:I am not sure what the desired behaviour is, maybe either:
list[Any]
.System Information
Additional Context
Example Code:
Upvote & Fund