Skip to content

Commit

Permalink
fix: generate unique RMQ message id, correct FastAPI error
Browse files Browse the repository at this point in the history
  • Loading branch information
Lancetnik committed Jul 27, 2023
1 parent 70227f4 commit 745c223
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion propan/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from unittest.mock import Mock

__version__ = "0.1.5.14"
__version__ = "0.1.5.15"


INSTALL_MESSAGE = (
Expand Down
8 changes: 4 additions & 4 deletions propan/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ def is_installed(package: str) -> bool:

if FASTAPI_V2:
from fastapi._compat import _normalize_errors
from fastapi.exceptions import ResponseValidationError
from fastapi.exceptions import RequestValidationError

def raise_fastapi_validation_error(errors: List[Any], body: AnyDict) -> Never:
raise ResponseValidationError(_normalize_errors(errors), body=body)
raise RequestValidationError(_normalize_errors(errors), body=body)

else:
from pydantic import ValidationError as ResponseValidationError
from pydantic import ValidationError as RequestValidationError
from pydantic import create_model

ROUTER_VALIDATION_ERROR_MODEL = create_model("PropanRoute")

def raise_fastapi_validation_error(errors: List[Any], body: AnyDict) -> Never:
raise ResponseValidationError(errors, ROUTER_VALIDATION_ERROR_MODEL)
raise RequestValidationError(errors, ROUTER_VALIDATION_ERROR_MODEL)


if PYDANTIC_V2:
Expand Down
2 changes: 1 addition & 1 deletion propan/brokers/rabbit/rabbit_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ async def _parse_message(
body=message.body,
headers=message.headers,
reply_to=message.reply_to or "",
message_id=message.message_id,
message_id=message.message_id or str(uuid4()),
content_type=message.content_type or "",
raw_message=message,
)
Expand Down
4 changes: 2 additions & 2 deletions tests/fastapi/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient

from propan._compat import ResponseValidationError
from propan._compat import RequestValidationError
from propan.fastapi import KafkaRouter
from propan.test import TestKafkaBroker
from propan.test.kafka import build_message
Expand Down Expand Up @@ -87,7 +87,7 @@ async def handler(a: int, b: str):

msg = build_message("Hello", "test")

with pytest.raises(ResponseValidationError):
with pytest.raises(RequestValidationError):
await handler(msg, reraise_exc=True)


Expand Down

0 comments on commit 745c223

Please sign in to comment.