Skip to content

Commit f28c414

Browse files
use BeforeValidator for country codes
1 parent 476e538 commit f28c414

File tree

1 file changed

+6
-10
lines changed
  • packages/settings-library/src/settings_library

1 file changed

+6
-10
lines changed

packages/settings-library/src/settings_library/twilio.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88

99
from typing import Annotated, TypeAlias
1010

11-
from pydantic import Field, StringConstraints, TypeAdapter, field_validator
11+
from pydantic import BeforeValidator, Field, StringConstraints, TypeAdapter
1212

1313
from .base import BaseCustomSettings
1414

15-
1615
# Based on https://countrycode.org/
17-
CountryCodeStr: TypeAlias = Annotated[str, StringConstraints(strip_whitespace=True, pattern=r"^\d{1,4}")]
16+
CountryCodeStr: TypeAlias = Annotated[
17+
str,
18+
BeforeValidator(str),
19+
StringConstraints(strip_whitespace=True, pattern=r"^\d{1,4}"),
20+
]
1821

1922

2023
class TwilioSettings(BaseCustomSettings):
@@ -30,13 +33,6 @@ class TwilioSettings(BaseCustomSettings):
3033
"See https://support.twilio.com/hc/en-us/articles/223133767-International-support-for-Alphanumeric-Sender-ID",
3134
)
3235

33-
34-
@field_validator("TWILIO_COUNTRY_CODES_W_ALPHANUMERIC_SID_SUPPORT", mode="before")
35-
@classmethod
36-
def _parse_country_codes_from_env(cls, v):
37-
return [str(cc) for cc in v]
38-
39-
4036
def is_alphanumeric_supported(self, phone_number: str) -> bool:
4137
# Some countries do not support alphanumeric serder ID
4238
#

0 commit comments

Comments
 (0)