cohere-python icon indicating copy to clipboard operation
cohere-python copied to clipboard

Pydantic V2 warning

Open n1lanjan opened this issue 1 year ago • 4 comments

SDK Version (required) Provide the version you are using.

❯ python
Python 3.11.4 (main, Feb  2 2024, 19:01:43) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cohere
/user/home/.venv/lib/python3.11/site-packages/pydantic/_internal/_config.py:341: UserWarning: Valid config keys have changed in V2:
* 'allow_population_by_field_name' has been renamed to 'populate_by_name'
* 'smart_union' has been removed
  warnings.warn(message, UserWarning)
>>> print(cohere.__version__)
5.8.0
>>> import pydantic
>>> pydantic.VERSION
'2.8.2'

Describe the bug

I am getting this warning while trying to use the library.

.venv/lib/python3.11/site-packages/pydantic/_internal/_config.py:341: UserWarning: Valid config keys have changed in V2:
* 'allow_population_by_field_name' has been renamed to 'populate_by_name'
* 'smart_union' has been removed
  warnings.warn(message, UserWarning)

This warning is triggering from the code below:

  • https://github.com/cohere-ai/cohere-python/blob/540207821d15fcf933935e44f76a07cd69e53465/src/cohere/core/pydantic_utilities.py#L85-L90

I proposed a PR, please review

  • https://github.com/cohere-ai/cohere-python/pull/560

n1lanjan avatar Aug 10 '24 16:08 n1lanjan

Thanks @n1lanjan we are looking into this!

billytrend-cohere avatar Aug 13 '24 16:08 billytrend-cohere

This is now fixed in the latest version of the sdk! thanks @n1lanjan

billytrend-cohere avatar Sep 05 '24 19:09 billytrend-cohere

The latest version (5.9.1) still triggers deprecation warnings with Pydantic V2 (2.8.2). You can see this if you import the Cohere library while elevating warnings to errors (like we do in our test suite):

$ python -W all -c 'import cohere'
<path>/.venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py:273: PydanticDeprecatedSince20: `json_encoders` is deprecated. See https://docs.pydantic.dev/2.8/concepts/serialization/#custom-serializers for alternatives. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.8/migration/
  warnings.warn(
<path>/.venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py:273: PydanticDeprecatedSince20: `json_encoders` is deprecated. See https://docs.pydantic.dev/2.8/concepts/serialization/#custom-serializers for alternatives. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.8/migration/
  warnings.warn(
<path>/.venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py:273: PydanticDeprecatedSince20: `json_encoders` is deprecated. See https://docs.pydantic.dev/2.8/concepts/serialization/#custom-serializers for alternatives. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.8/migration/
  warnings.warn(
<path>/.venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py:273: PydanticDeprecatedSince20: `json_encoders` is deprecated. See https://docs.pydantic.dev/2.8/concepts/serialization/#custom-serializers for alternatives. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.8/migration/
  warnings.warn(
<path>/.venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py:273: PydanticDeprecatedSince20: `json_encoders` is deprecated. See https://docs.pydantic.dev/2.8/concepts/serialization/#custom-serializers for alternatives. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.8/migration/
  warnings.warn(
<path>/.venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py:273: PydanticDeprecatedSince20: `json_encoders` is deprecated. See https://docs.pydantic.dev/2.8/concepts/serialization/#custom-serializers for alternatives. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.8/migration/
  warnings.warn(
<path>/.venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py:273: PydanticDeprecatedSince20: `json_encoders` is deprecated. See https://docs.pydantic.dev/2.8/concepts/serialization/#custom-serializers for alternatives. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.8/migration/
  warnings.warn(
<path>/.venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py:273: PydanticDeprecatedSince20: `json_encoders` is deprecated. See https://docs.pydantic.dev/2.8/concepts/serialization/#custom-serializers for alternatives. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.8/migration/
  warnings.warn(
<path>/.venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py:273: PydanticDeprecatedSince20: `json_encoders` is deprecated. See https://docs.pydantic.dev/2.8/concepts/serialization/#custom-serializers for alternatives. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.8/migration/
  warnings.warn(
<path>/.venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py:273: PydanticDeprecatedSince20: `json_encoders` is deprecated. See https://docs.pydantic.dev/2.8/concepts/serialization/#custom-serializers for alternatives. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.8/migration/
  warnings.warn(
<path>/.venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py:273: PydanticDeprecatedSince20: `json_encoders` is deprecated. See https://docs.pydantic.dev/2.8/concepts/serialization/#custom-serializers for alternatives. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.8/migration/
  warnings.warn(

Tenzer avatar Sep 06 '24 08:09 Tenzer

Thanks for the repro @Tenzer, looking into it!

billytrend-cohere avatar Sep 06 '24 13:09 billytrend-cohere