Skip to content

copy_on_model_validation config doesn't copy List field anymore in v1.9.0 #3641

@NunchakusLei

Description

@NunchakusLei

Checks

  • I added a descriptive title to this issue
  • I have searched (google, github) for similar issues and couldn't find anything
  • I have read and followed the docs and still think this is a bug

Bug

The output of python -c "import pydantic.utils; print(pydantic.utils.version_info())" when I use v1.9.0a1,

             pydantic version: 1.9.0a1
            pydantic compiled: True
                 install path: <*my-project-dir*>/venv/lib/python3.9/site-packages/pydantic
               python version: 3.9.9 (main, Nov 16 2021, 03:05:18)  [GCC 7.5.0]
                     platform: Linux-5.4.0-91-generic-x86_64-with-glibc2.27
     optional deps. installed: ['typing-extensions']

The output of python -c "import pydantic.utils; print(pydantic.utils.version_info())" when I use v1.9.0,

             pydantic version: 1.9.0
            pydantic compiled: True
                 install path: <*my-project-dir*>/venv/lib/python3.9/site-packages/pydantic
               python version: 3.9.9 (main, Nov 16 2021, 03:05:18)  [GCC 7.5.0]
                     platform: Linux-5.4.0-91-generic-x86_64-with-glibc2.27
     optional deps. installed: ['typing-extensions']

Looks like there is accidental behaviour change from v1.9.0a1 to v1.9.0 regarding the copy_on_model_validation config.

from pydantic import BaseModel
from typing import List


class A(BaseModel):
    name: str
    
    class Config:
        copy_on_model_validation = True  # Default behaviour
        

class B(BaseModel):
    list_a: List[A]


a = A(name="a")
b = B(list_a=[a])

print(a)
print(b)
a.name = "b"  # make a change to variable a's field
print(a)
print(b)

The output using v1.9.0a1,

A(name='a')
B(list_a=[A(name='a')])
A(name='b')
B(list_a=[A(name='a')])

The output using v1.9.0 changed to,

A(name='a')
B(list_a=[A(name='a')])
A(name='b')
B(list_a=[A(name='b')])

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug V1Bug related to Pydantic V1.X

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions