From bcccea3ef31c777b73cba41a6255cd866bf87237 Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Fri, 1 Mar 2024 08:06:21 +0100 Subject: [PATCH] Made runserver close database connections from migration checks. --- django/core/management/commands/runserver.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/django/core/management/commands/runserver.py b/django/core/management/commands/runserver.py index 26bbf29d68..132ee4c079 100644 --- a/django/core/management/commands/runserver.py +++ b/django/core/management/commands/runserver.py @@ -8,6 +8,7 @@ from datetime import datetime from django.conf import settings from django.core.management.base import BaseCommand, CommandError from django.core.servers.basehttp import WSGIServer, get_internal_wsgi_application, run +from django.db import connections from django.utils import autoreload from django.utils.regex_helper import _lazy_re_compile @@ -134,6 +135,9 @@ class Command(BaseCommand): # Need to check migrations here, so can't use the # requires_migrations_check attribute. self.check_migrations() + # Close all connections opened during migration checking. + for conn in connections.all(initialized_only=True): + conn.close() try: handler = self.get_handler(*args, **options)