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

RuntimeError: Unable to apply constraint strict to schema lax-or-strict when trying to set strictness on enum fields #7759

Closed
1 task done
lovetheguitar opened this issue Oct 6, 2023 · 3 comments · Fixed by #7761
Assignees
Labels
bug V2 Bug related to Pydantic V2

Comments

@lovetheguitar
Copy link

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

To allow "enum matching" from json input, I depend on setting enum field validation to strict=False.

This worked fine with pydantic 2.1.0.

Expectation would be that this works for enums. 😄

Thanks for your great work.

Example Code

import enum
from pydantic import BaseModel, ConfigDict, Field


class Demo(enum.Enum):
    A = 0
    B = 1


class User(BaseModel):
    model_config = ConfigDict(strict=True)
    name: str
    age: int = Field(strict=False)
    this_works: Demo
    this_does_not: Demo = Field(strict=False)  # comment this to make it work

Python, Pydantic & OS Version

pydantic version: 2.4.2
        pydantic-core version: 2.10.1
          pydantic-core build: profile=release pgo=false
                 install path: C:\Users\UserName\AppData\Local\pypoetry\Cache\virtualenvs\package-name-oKTDepZE-py3.8\Lib\site-packages\pydantic
               python version: 3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)]
                     platform: Windows-10-10.0.22621-SP0
             related packages: typing_extensions-4.8.0
@lovetheguitar lovetheguitar added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Oct 6, 2023
@sydney-runkle sydney-runkle self-assigned this Oct 6, 2023
@sydney-runkle sydney-runkle removed the pending Awaiting a response / confirmation label Oct 6, 2023
@sydney-runkle
Copy link
Member

Hi @lovetheguitar,

Thanks for reporting this! This does seem to be a bug 🐛. I'll look into a fix and keep you updated on this thread 👍.

@lovetheguitar
Copy link
Author

@sydney-runkle Thanks for the blazingly fast fix! 😺

How does the release process work for pydantic? When approximately will this be released?

@sydney-runkle
Copy link
Member

@lovetheguitar sure thing! Thanks again for the bug report 😄.

We generally have been adding new releases approximately monthly, but if you want to use our latest version (with the bug fix), you can pull down our latest changes from the main branch.

You can see more about our release timeline here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V2 Bug related to Pydantic V2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants