Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate prefect-email to pydantic2 #13654

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading