Skip to content

Commit

Permalink
migrate prefect-email to pydantic2 (#13654)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaazzam authored May 30, 2024
1 parent 6831c4d commit 07ae92f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
16 changes: 6 additions & 10 deletions src/integrations/prefect-email/prefect_email/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@
from smtplib import SMTP, SMTP_SSL
from typing import Optional, Union

from pydantic import VERSION as PYDANTIC_VERSION
from pydantic import Field, SecretStr, field_validator

from prefect.blocks.core import Block

if PYDANTIC_VERSION.startswith("2."):
from pydantic.v1 import Field, SecretStr, validator
else:
from pydantic import Field, SecretStr, validator


class SMTPType(Enum):
"""
Expand Down Expand Up @@ -133,15 +128,16 @@ class EmailServerCredentials(Block):
title="SMTP Port",
)

@validator("smtp_server", pre=True)
def _cast_smtp_server(cls, value):
@field_validator("smtp_server", mode="before")
def _cast_smtp_server(cls, value: str):
"""
Cast the smtp_server to an SMTPServer Enum member, if valid.
"""
return _cast_to_enum(value, SMTPServer)

@validator("smtp_type", pre=True)
def _cast_smtp_type(cls, value):
@field_validator("smtp_type", mode="before")
@classmethod
def _cast_smtp_type(cls, value: str):
"""
Cast the smtp_type to an SMTPType Enum member, if valid.
"""
Expand Down
2 changes: 1 addition & 1 deletion src/integrations/prefect-email/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from prefect.testing.utilities import prefect_test_harness


@pytest.fixture(autouse=True)
@pytest.fixture(autouse=True, scope="session")
def prefect_db():
with prefect_test_harness():
yield
Expand Down

0 comments on commit 07ae92f

Please sign in to comment.