Skip to content

Commit

Permalink
fix: pydantic v2 Warnings: The dict method is deprecated; use model_d…
Browse files Browse the repository at this point in the history
…ump instead
  • Loading branch information
bVdCreations committed Jan 10, 2024
1 parent fccd391 commit a481258
Showing 1 changed file with 6 additions and 1 deletion.
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

0 comments on commit a481258

Please sign in to comment.