Showing error message without saving object.

Hi, I am making some changes in save_model method of django admin. However, I cannot show error message without saving object, it is saving object and then showing custom error message.
admin.py

def save_model(self, request: Any, obj: News, form: Any, change: Any) -> None:
        if not obj.id:
            obj.author = request.user

            # generate unique short slug
            short_slug = uuid.uuid4().hex[:6]
            while News.objects.filter(short_slug=short_slug).exists():
                short_slug = uuid.uuid4().hex[:6]
            obj.short_slug = short_slug
        try:
            super().save_model(request, obj, form, change)
            self.send_telegram_news(obj)
            self.set_translatable_tags(obj)
        except Exception as e:
            messages.set_level(request, messages.ERROR)
            err_msg = f"Error: <<{e!s}>>"
            messages.add_message(request, messages.ERROR, err_msg)

For example, when getting error from self.send_telegram_news(obj) I need to show error message without saving it. Is it possible to prevent to save when getting error.

It depends - does your send_telegram_news method require that the data already be saved? If not, then you can reverse the order of the calls to super.save_model and the call to send_telegram_news.

Your other option, if there is a dependency between the two, would be to create a transaction inside the try and roll it back in the except.

Yes, the data should be saved before save_telegram_news method is called, but when it throws error, then, need to roll it back. Actually in settings database request set to atomic, because of using my own try/except django doesn’t know error that’s why saving the data.
How can I roll the transaction back manually ?

You can still have Django handle it by re-raising the exception in your except block.

See Controlling transactions explicitly for the docs and examples of handling transactions manually.