Skip to content

Commit e86ccbc

Browse files
authored
[Core] add deprecation warning for pydantic v1 (#59703)
related to #58876 ```bash ❯ python -c " import ray # Temporarily patch to test the warning shows from ray._common import pydantic_compat original = pydantic_compat.IS_PYDANTIC_2 pydantic_compat.IS_PYDANTIC_2 = False # Simulate Pydantic v1 ray.init() ray.shutdown() pydantic_compat.IS_PYDANTIC_2 = original " 2025-12-26 22:33:01,387 INFO worker.py:1811 -- Connecting to existing Ray cluster at address: 172.31.7.228:6379... 2025-12-26 22:33:01,407 INFO worker.py:1991 -- Connected to Ray cluster. View the dashboard at 127.0.0.1:8265 /home/ubuntu/ray/python/ray/_private/worker.py:2039: FutureWarning: Tip: In future versions of Ray, Ray will no longer override accelerator visible devices env var if num_gpus=0 or num_gpus=None (default). To enable this behavior and turn off this error message, set RAY_ACCEL_ENV_VAR_OVERRIDE_ON_ZERO=0 warnings.warn( /home/ubuntu/ray/python/ray/_private/worker.py:2050: FutureWarning: Pydantic v1 is deprecated and will no longer be supported in Ray 2.56. Please upgrade to Pydantic v2 by running `pip install -U pydantic`. See #58876 for more details. warnings.warn( ~/ray │ on 58876-abrar-pydantic *91 " ``` --------- Signed-off-by: abrar <abrar@anyscale.com>
1 parent b889743 commit e86ccbc

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

doc/source/ray-overview/installation.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ Installing Ray
1313
Ray currently officially supports x86_64, aarch64 (ARM) for Linux, and Apple silicon (M1) hardware.
1414
Ray on Windows is currently in beta.
1515

16+
.. warning::
17+
**Pydantic v1 Deprecation Notice:** Pydantic v1 is deprecated and Ray will drop support for it in
18+
version 2.56. If you're using Pydantic v1, upgrade to Pydantic v2 by running ``pip install -U pydantic``.
19+
See `GitHub issue #58876 <https://github.com/ray-project/ray/issues/58876>`_ for more details.
20+
1621
Official Releases
1722
-----------------
1823

doc/source/serve/advanced-guides/app-builder-guide.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ Notice that the "Hello from config" message is printed from within the deploymen
7777
(typed-app-builders)=
7878
### Typing arguments with Pydantic
7979

80+
:::{warning}
81+
**Pydantic v1 Deprecation Notice:** Pydantic v1 is deprecated and Ray will drop support for it in version 2.56. If you're using Pydantic v1, upgrade to Pydantic v2 by running `pip install -U pydantic`. See [GitHub issue #58876](https://github.com/ray-project/ray/issues/58876) for more details.
82+
:::
83+
8084
To avoid writing logic to parse and validate the arguments by hand, define a [Pydantic model](https://pydantic-docs.helpmanual.io/usage/models/) as the single input parameter's type to your application builder function (the parameter must be type annotated).
8185
Arguments are passed the same way, but the resulting dictionary is used to construct the Pydantic model using `model.parse_obj(args_dict)`.
8286

python/ray/_common/pydantic_compat.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# ruff: noqa
2+
from typing import Optional
23
import packaging.version
34

45
# Pydantic is a dependency of `ray["default"]` but not the minimal installation,
@@ -12,6 +13,13 @@
1213
PYDANTIC_INSTALLED = False
1314

1415

16+
PYDANTIC_MAJOR_VERSION: Optional[int] = (
17+
packaging.version.parse(pydantic.__version__).major
18+
if PYDANTIC_INSTALLED and hasattr(pydantic, "__version__")
19+
else None
20+
)
21+
22+
1523
if not PYDANTIC_INSTALLED:
1624
IS_PYDANTIC_2 = False
1725
BaseModel = None

python/ray/_private/worker.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,6 +2044,21 @@ def sigterm_handler(signum, frame):
20442044
FutureWarning,
20452045
)
20462046

2047+
# Check for Pydantic v1 and emit deprecation warning
2048+
from ray._common.pydantic_compat import PYDANTIC_MAJOR_VERSION
2049+
2050+
if (
2051+
PYDANTIC_MAJOR_VERSION
2052+
and PYDANTIC_MAJOR_VERSION == 1
2053+
and log_once("pydantic_v1_deprecation")
2054+
):
2055+
warnings.warn(
2056+
"Pydantic v1 is deprecated and will no longer be supported in Ray 2.56. "
2057+
"Please upgrade to Pydantic v2 by running `pip install pydantic>=2`. "
2058+
"See https://github.com/ray-project/ray/issues/58876 for more details.",
2059+
FutureWarning,
2060+
)
2061+
20472062
node_id = global_worker.core_worker.get_current_node_id()
20482063
global_node_address_info = _global_node.address_info.copy()
20492064
global_node_address_info["webui_url"] = _remove_protocol_from_url(dashboard_url)

0 commit comments

Comments
 (0)