diff --git a/pyproject.toml b/pyproject.toml index deac1f1..9de1a16 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ maintainers = [{name = "Vadim Kozyrevskiy", email = "vadikko2@mail.ru"}] name = "python-cqrs" readme = "README.md" requires-python = ">=3.10" -version = "4.6.3" +version = "4.6.4" [project.optional-dependencies] aiobreaker = ["aiobreaker>=0.3.0"] diff --git a/src/cqrs/message_brokers/protocol.py b/src/cqrs/message_brokers/protocol.py index 7267ae1..744fd5b 100644 --- a/src/cqrs/message_brokers/protocol.py +++ b/src/cqrs/message_brokers/protocol.py @@ -2,6 +2,7 @@ import dataclasses import typing import uuid +from dataclass_wizard import asdict @dataclasses.dataclass @@ -28,7 +29,7 @@ def to_dict(self) -> dict[str, typing.Any]: Returns: A dictionary containing all fields of the message instance. """ - return dataclasses.asdict(self) + return asdict(self) class MessageBroker(abc.ABC): diff --git a/src/cqrs/saga/storage/sqlalchemy.py b/src/cqrs/saga/storage/sqlalchemy.py index fbeded7..3ab5379 100644 --- a/src/cqrs/saga/storage/sqlalchemy.py +++ b/src/cqrs/saga/storage/sqlalchemy.py @@ -1,8 +1,10 @@ import datetime import logging +import os import typing import uuid +import dotenv import sqlalchemy from sqlalchemy import func from sqlalchemy.exc import SQLAlchemyError @@ -17,12 +19,23 @@ Base = registry().generate_base() logger = logging.getLogger(__name__) +dotenv.load_dotenv() + DEFAULT_SAGA_EXECUTION_TABLE_NAME = "saga_executions" DEFAULT_SAGA_LOG_TABLE_NAME = "saga_logs" +SAGA_EXECUTION_TABLE_NAME = os.getenv( + "CQRS_SAGA_EXECUTION_TABLE_NAME", + DEFAULT_SAGA_EXECUTION_TABLE_NAME, +) +SAGA_LOG_TABLE_NAME = os.getenv( + "CQRS_SAGA_LOG_TABLE_NAME", + DEFAULT_SAGA_LOG_TABLE_NAME, +) + class SagaExecutionModel(Base): - __tablename__ = DEFAULT_SAGA_EXECUTION_TABLE_NAME + __tablename__ = SAGA_EXECUTION_TABLE_NAME id = sqlalchemy.Column( sqlalchemy.Uuid, @@ -68,7 +81,7 @@ class SagaExecutionModel(Base): class SagaLogModel(Base): - __tablename__ = DEFAULT_SAGA_LOG_TABLE_NAME + __tablename__ = SAGA_LOG_TABLE_NAME id = sqlalchemy.Column( sqlalchemy.BigInteger(), @@ -80,7 +93,7 @@ class SagaLogModel(Base): ) saga_id = sqlalchemy.Column( sqlalchemy.Uuid, - sqlalchemy.ForeignKey(f"{DEFAULT_SAGA_EXECUTION_TABLE_NAME}.id"), + sqlalchemy.ForeignKey(f"{SAGA_EXECUTION_TABLE_NAME}.id"), nullable=False, comment="Saga ID", ) diff --git a/tests/unit/test_dcevent_from_dict_recursive.py b/tests/unit/test_dcevent_from_dict_recursive.py index 95ee148..91464e9 100644 --- a/tests/unit/test_dcevent_from_dict_recursive.py +++ b/tests/unit/test_dcevent_from_dict_recursive.py @@ -13,7 +13,7 @@ import pytest -from cqrs.events.event import DCEvent, DCDomainEvent, DCNotificationEvent +from cqrs.events.event import DCDomainEvent, DCNotificationEvent # ============================================================================ @@ -22,7 +22,7 @@ @dataclasses.dataclass(frozen=True) -class NestedData(DCEvent): +class NestedData: """Nested dataclass for testing recursive conversion.""" nested_id: uuid.UUID