KEMBAR78
Weird error message on creating a generic RootModel · Issue #8712 · pydantic/pydantic · GitHub
Skip to content

Weird error message on creating a generic RootModel #8712

@JensHeinrich

Description

@JensHeinrich

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

When creating a generic RootModel without providing the generic to the model in the class inheritance RootModelRootType is mentioned in the error message, which is somewhat misleading.

I would expect RootModelRootType to be stripped from suggested types and maybe if possible to mention the needed parametrization of the RootModel itself

Example Code

from typing import Generic, TypeVar
from pydantic import BaseModel, RootModel

T_ = TypeVar("T_", bound=BaseModel)


class GenericRootModel(RootModel, Generic[T_]):
    root: T_ | int

Python, Pydantic & OS Version

pydantic version: 2.6.0
        pydantic-core version: 2.16.1
          pydantic-core build: profile=release pgo=true
                 install path: $HOME/pyjcsidm/.venv/lib/python3.11/site-packages/pydantic
               python version: 3.11.6 (main, Oct  8 2023, 05:06:43) [GCC 13.2.0]
                     platform: Linux-6.2.0-26-generic-x86_64-with-glibc2.38
             related packages: mypy-1.8.0 email-validator-2.1.0.post1 typing_extensions-4.9.0 pydantic-settings-2.1.0
                       commit: unknown

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions