From c0ffaffeabeda41a0bb81025cf99af4572a6aa98 Mon Sep 17 00:00:00 2001 From: Cameron Hyde Date: Sat, 4 Jan 2025 11:04:41 +1000 Subject: [PATCH] Refresh db connections before runserver --- app/app/cli.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/app/cli.py b/app/app/cli.py index ad32396..f7ba95d 100644 --- a/app/app/cli.py +++ b/app/app/cli.py @@ -12,6 +12,8 @@ def main(): """CLI entry point for running the development server.""" try: from django.core.management import execute_from_command_line + from django.db import connections + from django.apps import apps except ImportError as exc: raise ImportError( "Couldn't import Django. Make sure it's installed and " @@ -28,6 +30,9 @@ def main(): if len(sys.argv) > 2: os.environ["LAB_CONTENT_ENTRYPOINT"] = sys.argv[2] execute_from_command_line(["manage.py", "migrate"]) + for conn in connections.all(): + conn.close() + apps.clear_cache() execute_from_command_line(["manage.py", "runserver"]) else: print(f"Unknown command: {sys.argv[1]}")