Skip to content

Bump Pydantic version to 2.x #45

Description

@tr11

Pydantic released their 2.x version earlier last month, which is causing a little bit of issues when trying to use permit on projects that already use the new version, namely with fastapi.

Would it be possible to bump the requirements to update pydantic to >= 2.0? They offer an easy way to use it with the new 2.x branch, according to their docs:

The Pydantic V2 package also continues to provide access to the Pydantic V1 API by importing through pydantic.v1. For example, you can use the BaseModel class from Pydantic V1 instead of the Pydantic V2 pydantic.BaseModel class:

from pydantic.v1 import BaseModel

Activity

  1. asafc commented on Sep 20, 2023

    @asafc
    Contributor

    hi @tr11, thanks for opening this issue, we are looking into a solution!

    Just FYI, the suggested solution won't work because it forces the users of the permit library to upgrade pydantic to v2.
    They might not be able to, because a migration might be quite difficult depending on the project.

    What we'll do is either build a cross compat layer or remove pydantic altogether from this SDK.

  2. self-assigned this
    on Sep 28, 2026
  3. zeevmoney commented on Sep 28, 2026

    @zeevmoney
    Member

    Thanks @tr11 for raising this, and sorry it stayed open so long after it was resolved.

    Pydantic 2 has been supported since permit 2.1.0. As @asafc mentioned above, we did not raise the minimum to pydantic>=2, because that would have forced every user to migrate. Instead, #46 removed the <2 upper bound and added a compatibility layer: under pydantic 2 the SDK loads its models from pydantic.v1, which is the approach you suggested. That means permit installs and runs next to FastAPI and other pydantic 2 code.

    #126, now merged to main and shipping in permit 3.0.0, finishes this work:

    • It fixes the one remaining spot that broke under pydantic 2: authorized_users() used an unguarded parse_obj_as import.
    • CI now requires the test suite to pass on both pydantic 1 and pydantic 2, on every Python from 3.10 to 3.14.

    One related note: the SDK's models are still pydantic v1-style models under pydantic 2, so recent FastAPI versions won't accept them directly as request or response models. Convert them with .dict(), or wrap them in your own v2 model. Moving the models to native pydantic 2 is planned separately.

    Closing as fixed. Please reopen if you hit a pydantic 2 conflict with a current release.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions