Skip to content

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

Closed

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')])

Activity

  1. changed the title [-]copy_on_model_validation config doesn't copy List field anymore[/-] [+]copy_on_model_validation config doesn't copy List field anymore in v1.9.0[/+] on Jan 8, 2022
  2. added a commit that references this issue on Jan 9, 2022
    ae40832
  3. added this to the v1.9.1 milestone on Apr 2, 2022
  4. added a commit that references this issue on May 11, 2022
    5490ad5
  5. added a commit that references this issue on May 13, 2022
    c49868a
  6. added a commit that references this issue on May 14, 2022
    952fad2
  7. added a commit that references this issue on Jun 24, 2022
    d2c8cd4
  8. NunchakusLei commented on Aug 19, 2022

    @NunchakusLei
    Author

    This issue happens again in the latest version 1.9.2.

  9. timkpaine commented on Aug 19, 2022

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

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