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

1.9.1 Breaking change with model deep copying #4092

Closed
3 tasks done
NotPeopling2day opened this issue May 19, 2022 · 11 comments
Closed
3 tasks done

1.9.1 Breaking change with model deep copying #4092

NotPeopling2day opened this issue May 19, 2022 · 11 comments
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@NotPeopling2day
Copy link

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

https://github.com/samuelcolvin/pydantic/pull/3642/files
The above PR changes the way models are copied and has created a breaking change in our code base. When running our test suite we now get the following error:

INTERNALERROR>   File "/Users/worx/ape/src/ape_test/providers.py", line 19, in __init__
INTERNALERROR>     super().__init__(**data)
INTERNALERROR>   File "pydantic/main.py", line 339, in pydantic.main.BaseModel.__init__
INTERNALERROR>   File "pydantic/main.py", line 1038, in pydantic.main.validate_model
INTERNALERROR>   File "pydantic/fields.py", line 857, in pydantic.fields.ModelField.validate
INTERNALERROR>   File "pydantic/fields.py", line 1074, in pydantic.fields.ModelField._validate_singleton
INTERNALERROR>   File "pydantic/fields.py", line 1121, in pydantic.fields.ModelField._apply_validators
INTERNALERROR>   File "pydantic/class_validators.py", line 313, in pydantic.class_validators._generic_validator_basic.lambda12
INTERNALERROR>   File "pydantic/main.py", line 679, in pydantic.main.BaseModel.validate
INTERNALERROR>   File "pydantic/main.py", line 605, in pydantic.main.BaseModel._copy_and_set_values
INTERNALERROR>   File "/Users/worx/.pyenv/versions/3.9.2/lib/python3.9/copy.py", line 146, in deepcopy
INTERNALERROR>     y = copier(x, memo)
INTERNALERROR>   File "/Users/worx/.pyenv/versions/3.9.2/lib/python3.9/copy.py", line 230, in _deepcopy_dict
INTERNALERROR>     y[deepcopy(key, memo)] = deepcopy(value, memo)
INTERNALERROR>   File "/Users/worx/.pyenv/versions/3.9.2/lib/python3.9/copy.py", line 151, in deepcopy
INTERNALERROR>     copier = getattr(x, "__deepcopy__", None)
INTERNALERROR>   File "/Users/worx/ape/src/ape/api/networks.py", line 183, in __getattr__
INTERNALERROR>     return self.get_network(network_name)
INTERNALERROR>   File "/Users/worx/ape/src/ape/api/networks.py", line 320, in get_network
INTERNALERROR>     raise NetworkNotFoundError(network_name)
INTERNALERROR> ape.exceptions.NetworkNotFoundError: No network named '--deepcopy--'.

Pinning to 1.9.0 as current fix.

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

pydantic version: 1.9.1
            pydantic compiled: True
                 install path: /Users/worx/.pyenv/versions/3.9.2/envs/ape/lib/python3.9/site-packages/pydantic
               python version: 3.9.2 (default, Dec  2 2021, 09:57:33)  [Clang 13.0.0 (clang-1300.0.29.3)]
                     platform: macOS-12.3.1-arm64-arm-64bit
     optional deps. installed: ['typing-extensions']
import pydantic

...
@NotPeopling2day NotPeopling2day added the bug V1 Bug related to Pydantic V1.X label May 19, 2022
@samuelcolvin
Copy link
Member

Thanks for reporting, please can you provide a self contained example that shows the error.

@timkpaine
Copy link
Contributor

I am experiencing the same, references that would've previously been carried through a hierarchy of types now get broken during validation. I will try to put together a repro and suggest changes to maintain the prior functionality

@timkpaine
Copy link
Contributor

ae40832

@timkpaine
Copy link
Contributor

here is a fine repro:
https://github.com/PrettyWood/pydantic/blob/ae408326e70d84510a8e25e8f6a6ae8871df2fd0/tests/test_main.py#L1564

That line was changed from is to is not. This is a breaking change in functionality

@samuelcolvin
Copy link
Member

Well that's not the same as the error shown above, that's just a change in behaviour.

@timkpaine
Copy link
Contributor

sure, but its a breaking change in behavior.

@timkpaine
Copy link
Contributor

#4093

@NotPeopling2day
Copy link
Author

Yeah, the breaking change in behavior on a minor release was my intention in creating the ticket, more info driven than anything. We've corrected the issue on our side by changing back to the previously default behavior for copy_on_model_validation. ApeWorX/ape#735 , without updating this setting in the config we end up seeing seg faults.

@orenwang
Copy link

I am experiencing the same. Had to downgrade to 1.9.0 to make my code work.

@gdalmau
Copy link

gdalmau commented Aug 17, 2022

@samuelcolvin @NotPeopling2day I think this issue can be closed since it was fixed in https://github.com/pydantic/pydantic/releases/tag/v1.9.2 with #4093

@samuelcolvin
Copy link
Member

Good catch, thanks.

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

No branches or pull requests

5 participants