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

Feature: Add optional to automatically nack on input validation fail #2069

Open
pafi-code opened this issue Feb 14, 2025 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@pafi-code
Copy link

pafi-code commented Feb 14, 2025

Is your feature request related to a problem? Please describe.
When I receive an invalid body and the pydantic validation fails of the input I would like to have to option to automatically nack the message. For now I'm using the decoder of the route as a workaround. (see below)

Describe the solution you'd like
I don't really know what the best solution would be here, but maybe some more flags for the route would suffice. (Even though I would agree that one wouldn't want to have millions of flags for creating an object)

Feature code example

async def _decoder(message: rabbit.RabbitMessage) -> ServiceInput:
    """Decode message with nack if it fails."""
    try:
        return ServiceInput.model_validate_json(message.body)
    except pydantic.ValidationError as error:
        _LOGGER.error(error)
        raise exceptions.NackMessage

rabbit.RabbitRoute(
                ...
                decoder=_decoder,
            )
@pafi-code pafi-code added the enhancement New feature or request label Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

1 participant