Skip to content

Compatibility Issue with Pydantic v2 – __root__ Usage Causing TypeError #1

Description

@JayShukla8

First off, thanks for the great work on this project!

Ran into this issue when trying to run the web interface

TypeError: To define root models, use pydantic.RootModel rather than a field called '__root__'

This issue is getting raised since in my system, the version of pydantic is v2.

And v2 seems to have removed support for defining root models using the __root__ field.
They now must be defined using pydantic.RootModel.

Atleast that's what ChatGPT told me.
Here's an example

# Pydantic v1 syntax (no longer valid in v2)
from pydantic import BaseModel

class MyModel(BaseModel):
    __root__: list[int]
from pydantic import RootModel

class MyModel(RootModel[list[int]]):
    pass

Suggested Solutions:

  • If this project is intended for Pydantic v1, it would be helpful to specify the Pydantic version in pyproject.toml or requirements.txt (e.g., pydantic<2.0).

  • If you’re planning to update for Pydantic v2 compatibility, the codebase will need to migrate to use RootModel

The issue got resolved by downgrading my pydantic version, so you can close this one.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions