Skip to content

Add failing test: duplicate typename__ when type implements multiple interfaces - #442

Open
magicmark wants to merge 1 commit into
mirumee:mainfrom
magicmark:fix/duplicate-typename-fields
Open

Add failing test: duplicate typename__ when type implements multiple interfaces#442
magicmark wants to merge 1 commit into
mirumee:mainfrom
magicmark:fix/duplicate-typename-fields

Conversation

@magicmark

@magicmark magicmark commented Jul 7, 2026

Copy link
Copy Markdown

When a concrete type implements multiple interfaces and a query spreads on both with __typename, codegen emits the field twice — which makes mypy blow up with Name "typename__" already defined [no-redef].

type Foo implements Bar & Baz { id: ID!, name: String! }

query GetFoo {
    foo {
        ... on Bar { __typename id }
        ... on Baz { __typename name }
    }
}

Actual:

class GetFooFoo(BaseModel):
    typename__: Literal["Foo"] = Field(alias="__typename")
    id: str
    typename__: Literal["Foo"] = Field(alias="__typename")
    name: str

Expected:

class GetFooFoo(BaseModel):
    typename__: Literal["Foo"] = Field(alias="__typename")
    id: str
    name: str

Works fine at runtime (pydantic is happy), but mypy won't accept it.

Fix is at magicmark#1 (on my fork for now — can't target a fork branch as base on upstream).

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9abe981c-f5eb-4484-b574-85e83c23245d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

When a concrete type implements multiple interfaces and a query uses inline
fragments on those interfaces (each selecting __typename), the codegen
produces duplicate typename__ fields in the generated Pydantic model. This
causes mypy to fail with: Name "typename__" already defined [no-redef]

Co-Authored-By: Claude <noreply@anthropic.com>
@magicmark
magicmark force-pushed the fix/duplicate-typename-fields branch from 8c93608 to 22e36c5 Compare July 7, 2026 21:46
@magicmark
magicmark marked this pull request as ready for review July 7, 2026 22:51
@magicmark

Copy link
Copy Markdown
Author

@mirumee any thoughts?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant