This is an automated email from the ASF dual-hosted git repository.

ephraimanierobi pushed a commit to branch v2-4-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 2c5b336db2a24837f1cfee44a96c063eff4ee9c9
Author: Ephraim Anierobi <[email protected]>
AuthorDate: Thu Oct 27 05:25:44 2022 +0100

    Fix IntegrityError during webserver startup (#27297)
    
    (cherry picked from commit 8f99c793ec4289f7fc28d890b6c2887f0951e09b)
---
 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 9d15d44b7d..ce45705ee0 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 9aa8e97885..0e15dda077 100644
--- a/tests/cli/commands/test_webserver_command.py
+++ b/tests/cli/commands/test_webserver_command.py
@@ -406,6 +406,7 @@ class TestCliWebServer:
                     '--access-logformat',
                     'custom_log_format',
                     'airflow.www.app:cached_app()',
+                    "--preload",
                 ],
                 close_fds=True,
             )

Reply via email to