transaction.set_rollback can do this.
class SomeCommand(BaseCommand):
@transaction.atomic
def handle(self, *args, **options):
# Doing some stuff, changing objects
if some_condition:
# Return, rolling back transaction when atomic block exits
transaction.set_rollback(True)
return
Quoting from the docs:
Setting the rollback flag to
Trueforces a rollback when exiting the innermost atomic block. This may be useful to trigger a rollback without raising an exception.