Skip to content

Commit

Permalink
fix field validationinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
giancarloromeo committed Nov 15, 2024
1 parent e079255 commit 9494bd3
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions packages/models-library/src/models_library/folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
from enum import auto
from typing import TypeAlias

from pydantic import BaseModel, ConfigDict, Field, PositiveInt, field_validator
from pydantic import (
BaseModel,
ConfigDict,
Field,
PositiveInt,
ValidationInfo,
field_validator,
)

from .access_rights import AccessRights
from .users import GroupID, UserID
Expand All @@ -24,16 +31,14 @@ class FolderQuery(BaseModel):

@field_validator("folder_id", mode="before")
@classmethod
def validate_folder_id(cls, value, values):
scope = values.get("folder_scope")
def validate_folder_id(cls, value, info: ValidationInfo):
scope = info.data.get("folder_scope")
if scope == FolderScope.SPECIFIC and value is None:
raise ValueError(
"folder_id must be provided when folder_scope is SPECIFIC."
)
msg = "folder_id must be provided when folder_scope is SPECIFIC."
raise ValueError(msg)
if scope != FolderScope.SPECIFIC and value is not None:
raise ValueError(
"folder_id should be None when folder_scope is not SPECIFIC."
)
msg = "folder_id should be None when folder_scope is not SPECIFIC."
raise ValueError(msg)
return value


Expand Down

0 comments on commit 9494bd3

Please sign in to comment.