From 71fd12f2606b01bff56087664a45c5dbf4890a29 Mon Sep 17 00:00:00 2001 From: Pierre Ducroquet Date: Wed, 18 May 2022 12:26:10 +0200 Subject: [PATCH] tenant_command: don't close sql sessions after each tenant (#65388) --- .../management/commands/tenant_command.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/hobo/multitenant/management/commands/tenant_command.py b/hobo/multitenant/management/commands/tenant_command.py index 5ce72ef..ec267e1 100644 --- a/hobo/multitenant/management/commands/tenant_command.py +++ b/hobo/multitenant/management/commands/tenant_command.py @@ -63,13 +63,6 @@ def run_command_from_argv(command, argv): '%s: %s: %s' % (connection.get_tenant(), e.__class__.__name__, exception_to_text(e)) ) return e - finally: - try: - connections.close_all() - except ImproperlyConfigured: - # Ignore if connections aren't setup at this point (e.g. no - # configured settings). - pass class Command(InteractiveTenantOption, BaseCommand): @@ -152,6 +145,12 @@ class Command(InteractiveTenantOption, BaseCommand): error = run_command_from_argv(klass, args) if error: errors.append(error) + try: + connections.close_all() + except ImproperlyConfigured: + # Ignore if connections aren't setup at this point (e.g. no + # configured settings). + pass if errors: self.stderr.write('Command failed on multiple tenants') sys.exit(1)