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

fix: pydantic v2 Warnings: The dict method is deprecated; use model_dump instead #49

Merged
Merged
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
7 changes: 6 additions & 1 deletion fastapi_events/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
from fastapi_events.typing import Event, EventName, Payload, PydanticModel
from fastapi_events.utils import strtobool

IS_PYDANTIC_V1 = False
try:
import pydantic # noqa: F401

HAS_PYDANTIC = True
IS_PYDANTIC_V1 = pydantic.VERSION.startswith("1.")
except ImportError:
HAS_PYDANTIC = False

Expand Down Expand Up @@ -141,7 +143,10 @@ def _validate_payload(
payload_schema_cls = payload_schema_registry.get(event_name)
if payload_schema_cls:
payload_schema_cls_dict_args = payload_schema_cls_dict_args or DEFAULT_PAYLOAD_SCHEMA_CLS_DICT_ARGS
payload = payload_schema_cls(**(payload or {})).dict(**payload_schema_cls_dict_args)
if IS_PYDANTIC_V1:
payload = payload_schema_cls(**(payload or {})).dict(**payload_schema_cls_dict_args)
else:
payload = payload_schema_cls(**(payload or {})).model_dump(**payload_schema_cls_dict_args)
else:
logger.debug("Payload schema for event %s not found. Skipping validation...", event_name)

Expand Down