Skip to content

Commit

Permalink
Refresh db connections before runserver
Browse files Browse the repository at this point in the history
  • Loading branch information
neoformit committed Jan 4, 2025
1 parent c7d0064 commit c0ffaff
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/app/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -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]}")
Expand Down

0 comments on commit c0ffaff

Please sign in to comment.