Pydantic.dataclasses.dataclass only supports init=False


Until last Friday (June 29, 2023), I had been successfully working with the RAY library in a Cluster. However, on June 30, 2023, I encountered the following error:

Traceback (most recent call last):
** File “/home/hadoop/venv/bin/ray”, line 5, in **
** from ray.scripts.scripts import main**
** File “/home/hadoop/venv/lib64/python3.7/site-packages/ray/scripts/”, line 2430, in **
** from ray.util.state.state_cli import (**
** File “/home/hadoop/venv/lib64/python3.7/site-packages/ray/util/state/”, line 1, in **
** from ray.util.state.api import (**
** File “/home/hadoop/venv/lib64/python3.7/site-packages/ray/util/state/”, line 17, in **
** from ray.util.state.common import (**
** File “/home/hadoop/venv/lib64/python3.7/site-packages/ray/util/state/”, line 120, in **
** @dataclass(init=True)**
** File “/home/hadoop/venv/lib64/python3.7/site-packages/pydantic/”, line 139, in dataclass**
** assert init is False, ‘pydantic.dataclasses.dataclass only supports init=False’**
AssertionError: pydantic.dataclasses.dataclass only supports init=False

Additionally, I observed that Pydantic released a new version on the same day, June 30. I’m uncertain if this could be the underlying cause of the issue.

Would you be able to assist me in resolving this error?

1 Like

Seems like you’re using Pydantic 2.x (which comes with some breaking changes)

I’d suggest you to try to downgrade Pydantic to 1.x

BTW there’s similar issue reported on Github:

We’ve merged the changes to make Ray compatible with Pydantic 2.5+. You can start using Pydantic 2.5+ with Ray 2.9, which should be out at the end of December.

These changes should also be in the Ray nightly, so feel free to try them out!

1 Like