Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DuplicatedTypeName exception raised for nested generics #2599

Open
bikeshedder opened this issue Mar 1, 2023 · 4 comments · May be fixed by #2606
Open

DuplicatedTypeName exception raised for nested generics #2599

bikeshedder opened this issue Mar 1, 2023 · 4 comments · May be fixed by #2606
Labels
area: generics bug Something isn't working

Comments

@bikeshedder
Copy link
Contributor

bikeshedder commented Mar 1, 2023

Using nested generics causes an invalid DuplicatedTypeName exception to be raised when using the same type twice.

Minimal reproducible example

from typing import Generic, TypeVar

import strawberry

T = TypeVar("T")

@strawberry.type
class Wrapper(Generic[T]):
    value: T

@strawberry.type
class Query:
    a: Wrapper[Wrapper[int]]
    b: Wrapper[Wrapper[int]]

schema = strawberry.Schema(query=Query)

Exception

strawberry.exceptions.duplicated_type_name.DuplicatedTypeName:
Type IntWrapperWrapper is defined multiple times in the schema

System Information

  • Operating system: Ubuntu 22.04.1 LTS
  • Strawberry version: The check was first introduced in 0.144 and up until 0.159 it fails.

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@bikeshedder bikeshedder added the bug Something isn't working label Mar 1, 2023
@patrick91 patrick91 linked a pull request Mar 2, 2023 that will close this issue
@yallxe
Copy link

yallxe commented May 30, 2023

Any updates on this?

@Skeen
Copy link
Member

Skeen commented Aug 17, 2023

I'm also encountering this, is there any known workaround?

@alidin000
Copy link

Any update on this?

@bellini666
Copy link
Member

bellini666 commented Jan 16, 2025

For that example, do specializing the wrapper works? e.g.

from typing import Generic, TypeVar

import strawberry

T = TypeVar("T")

@strawberry.type
class Wrapper(Generic[T]):
    value: T

@strawberry.type
class IntWrapper(Wrapper[int]):
    ...

@strawberry.type
class Query:
    a: Wrapper[IntWrapper]
    b: Wrapper[IntWrapper]

schema = strawberry.Schema(query=Query)

This still a bug, but maybe that's a possible workaround for now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: generics bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants