Skip to content

Commit bdb87a9

Browse files
committed
Update easyswitch/conf/base.py to include ValidationInfo in validate_default_provider method and change validate_all to validate_default
1 parent fd8c877 commit bdb87a9

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

easyswitch/conf/base.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pathlib import Path
88
from typing import Any, Dict, Optional, Type
99

10-
from pydantic import BaseModel, Field, field_validator, model_validator
10+
from pydantic import BaseModel, Field, field_validator, model_validator, ValidationInfo
1111

1212
from easyswitch.exceptions import ConfigurationError
1313
from easyswitch.types import Currency, Provider
@@ -61,7 +61,7 @@ class BaseConfigModel(BaseModel):
6161

6262
class Config:
6363
extra = 'forbid' # Undefined fields are not allowed
64-
validate_all = True
64+
validate_default = True
6565
use_enum_values = True
6666

6767

@@ -127,17 +127,20 @@ class RootConfig(BaseConfigModel):
127127
default_provider: Optional[Provider] = None
128128

129129
@field_validator('default_provider')
130-
def validate_default_provider(cls, v, values):
130+
@classmethod
131+
def validate_default_provider(cls, v, info: ValidationInfo):
131132
"""Ensure default provider is valid."""
132-
133+
133134
# Ensure default provider is in enabled providers
134-
if v is not None and 'providers' in values and v not in values['providers']:
135-
raise ValueError(
136-
f"Default provider {v} must be in enabled providers"
137-
)
135+
if v is not None:
136+
providers = info.data.get('providers')
137+
if providers and v not in providers:
138+
raise ValueError(
139+
f"Default provider {v} must be in enabled providers"
140+
)
138141

139142
# and in supported Providers
140-
if v not in Provider.__members__:
143+
if v is not None and v not in Provider.__members__:
141144
raise ValueError(
142145
f"Default provider {v} is not supported"
143146
)

0 commit comments

Comments
 (0)