Skip to content

pydantic v2 fails on model rebuild #7618

@zworkb

Description

@zworkb

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

pydantic version 2.4.0 fails at rebuilding a model.

the same code works with pydantic 2.3.0

steps with which I can reproduce the error on OSX and Linux:

python3 -m venv venv
. venv/bin/activate
pip install pydantic=="2.4.0"
python killpydantic.py

where killpydantic.py contains the code below

Example Code

from enum import Enum
from pydantic import BaseModel
    

class Alignment(Enum):
    LEFT = "PKTextAlignmentLeft"


class DateStyle(Enum):
    SHORT = "PKDateStyleShort"


class Field(BaseModel):
    i:int = 0
    textAlignment: Alignment = Alignment.LEFT  # when I comment out this line, it works


class DateField(Field):
    """"""
    # when I comment out one of these lines, it works
    dateStyle: DateStyle = DateStyle.SHORT
    timeStyle: DateStyle = DateStyle.SHORT
    

class Pass(BaseModel):
    # when I comment out one of these lines, it works
    relevantDate: DateField | str | None = None
    expirationDate: DateField | None = None 


Pass.model_rebuild(force=True)

Python, Pydantic & OS Version

OSX:

             pydantic version: 2.4.0
        pydantic-core version: 2.10.0
          pydantic-core build: profile=release pgo=false
                 install path: /Users/phil/tmp/schas1/venv/lib/python3.11/site-packages/pydantic
               python version: 3.11.3 (main, Apr  7 2023, 19:25:52) [Clang 14.0.0 (clang-1400.0.29.202)]
                     platform: macOS-13.2.1-x86_64-i386-64bit
             related packages: typing_extensions-4.8.0


LINUX:
             pydantic version: 2.4.0
        pydantic-core version: 2.10.0
          pydantic-core build: profile=release pgo=true
                 install path: /home/phil/dev/projects/edutap/apple-pass-creator-service/venv/lib/python3.10/site-packages/pydantic
               python version: 3.10.7 (main, May 29 2023, 13:51:48) [GCC 12.2.0]
                     platform: Linux-5.19.0-46-generic-x86_64-with-glibc2.36
             related packages: typing_extensions-4.8.0 fastapi-0.103.1

As stated above, everything works fine with pydantic 2.3.0

Metadata

Metadata

Assignees

Labels

bug V2Bug related to Pydantic V2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions