Skip to content

Commit c1906ca

Browse files
fix field validationinfo
1 parent 68523be commit c1906ca

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

packages/models-library/src/models_library/workspaces.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
from enum import auto
33
from typing import TypeAlias
44

5-
from pydantic import BaseModel, ConfigDict, Field, PositiveInt, field_validator
5+
from pydantic import (
6+
BaseModel,
7+
ConfigDict,
8+
Field,
9+
PositiveInt,
10+
ValidationInfo,
11+
field_validator,
12+
)
613

714
from .access_rights import AccessRights
815
from .users import GroupID
@@ -23,16 +30,14 @@ class WorkspaceQuery(BaseModel):
2330

2431
@field_validator("workspace_id", mode="before")
2532
@classmethod
26-
def validate_workspace_id(cls, value, values):
27-
scope = values.get("workspace_scope")
33+
def validate_workspace_id(cls, value, info: ValidationInfo):
34+
scope = info.data.get("workspace_scope")
2835
if scope == WorkspaceScope.SHARED and value is None:
29-
raise ValueError(
30-
"workspace_id must be provided when workspace_scope is SHARED."
31-
)
36+
msg = "workspace_id must be provided when workspace_scope is SHARED."
37+
raise ValueError(msg)
3238
if scope != WorkspaceScope.SHARED and value is not None:
33-
raise ValueError(
34-
"workspace_id should be None when workspace_scope is not SHARED."
35-
)
39+
msg = "workspace_id should be None when workspace_scope is not SHARED."
40+
raise ValueError(msg)
3641
return value
3742

3843

0 commit comments

Comments
 (0)