From 8f99c793ec4289f7fc28d890b6c2887f0951e09b Mon Sep 17 00:00:00 2001 From: Ephraim Anierobi Date: Thu, 27 Oct 2022 05:25:44 +0100 Subject: [PATCH] Fix IntegrityError during webserver startup (#27297) --- airflow/cli/commands/webserver_command.py | 6 ++++++ tests/cli/commands/test_webserver_command.py | 1 + 2 files changed, 7 insertions(+) diff --git a/airflow/cli/commands/webserver_command.py b/airflow/cli/commands/webserver_command.py index 9d15d44b7dfcd..ce45705ee0064 100644 --- a/airflow/cli/commands/webserver_command.py +++ b/airflow/cli/commands/webserver_command.py @@ -414,6 +414,12 @@ def webserver(args): run_args += ["airflow.www.app:cached_app()"] + # To prevent different workers creating the web app and + # all writing to the database at the same time, we use the --preload option. + # With the preload option, the app is loaded before the workers are forked, and each worker will + # then have a copy of the app + run_args += ['--preload'] + gunicorn_master_proc = None def kill_proc(signum, _): diff --git a/tests/cli/commands/test_webserver_command.py b/tests/cli/commands/test_webserver_command.py index 873661323406f..b81b7f6e33b60 100644 --- a/tests/cli/commands/test_webserver_command.py +++ b/tests/cli/commands/test_webserver_command.py @@ -405,6 +405,7 @@ def test_cli_webserver_args(self): "--access-logformat", "custom_log_format", "airflow.www.app:cached_app()", + "--preload", ], close_fds=True, )