Skip to content

0.1.4.0 (2023-06-26) PydanticV2

Compare
Choose a tag to compare
@Lancetnik Lancetnik released this 26 Jun 17:45
· 113 commits to main since this release

The main change in this update is the support for the PydanticV2 beta version.

Also, this update still supports Pydantic v1, so if something with PydanticV2 breaks you can simply roll it back - the latest Propan continues to work without changes.

Be careful: if you use Propan together with FastAPI when migrating to PydanticV2, you must install the version fastapi>=0.100.0b1, which is also compatible with both versions of Pydantic. However, if you are working on versions of FastAPI 0.9*, the current release is compatible with them as well (but only using PydanticV1).

All test suites work correctly with all variations of the dependencies and on all supported Python versions.

Other changes:

Improved compatibility with FastAPI:

  • PropanRouter supports top-level dependencies

    from propan.fastapi import RabbitRouter
    
    router = RabbitRouter(dependencies=[...])
    @router.event("test", dependencies=[...])
    async def handler(a: str, b: int):
         ...
  • You can test router.event using build_message directly

    import pytest, pydantic
    from propan.fastapi import RabbitRouter
    from propan.test.rabbit import build_message
    
    router = RabbitRouter()
    
    @router.event("test")
    async def handler(a: str, b: int):
         ...
    
    with pytest.raises(pydantic.ValidationError):
    handler(build_message("Hello", "test"), reraise_exc=True)

Implemented BrokerRouter for the convenience of splitting the application code into imported submodules.

from propan import RabbitBroker, RabbitRouter

router = RabbitRouter(prefix="user/")

@router.handle("created")
async def handle_user_created_event(user_id: str):
     ...

broker = RabbitBroker()
broker.include_router(router)

Added documentation section about custom message serialization (using the example with Protobuf).

And also updated several other sections of the documentation, fixed several non-critical bugs, removed RabbitBroker deprecated methods, and increased test coverage of rare scenarios.