diff --git a/litellm/proxy/proxy_cli.py b/litellm/proxy/proxy_cli.py index d5f64a6f686..e14cfb22831 100644 --- a/litellm/proxy/proxy_cli.py +++ b/litellm/proxy/proxy_cli.py @@ -203,6 +203,14 @@ def deprecated_v2_flag_passed_on_cli() -> bool: return ctx.get_parameter_source("use_v2_migration_resolver") is ParameterSource.COMMANDLINE +def _print_enforce_prisma_migration_check_notice() -> None: + print_startup_message( + "\033[1;33mLiteLLM Proxy: --enforce_prisma_migration_check is " + "deprecated and has no effect, because the proxy always exits " + "when database setup fails at startup. You can safely remove it.\033[0m", + ) + + class ProxyInitializationHelpers: @staticmethod def echo_litellm_version(): @@ -1177,6 +1185,9 @@ def run_server( return if model and "ollama" in model and api_base is None: ProxyInitializationHelpers.run_ollama_serve() + if enforce_prisma_migration_check and (health is True or test is True): + # --health and --test return before the config is read, where a server start emits the notice + _print_enforce_prisma_migration_check_notice() if health is True: ProxyInitializationHelpers.run_health_check(host, port) return @@ -1360,11 +1371,7 @@ def run_server( # After the config is read, so a json_logs set only in the config applies to this notice too. if enforce_prisma_migration_check: - print_startup_message( - "\033[1;33mLiteLLM Proxy: --enforce_prisma_migration_check is " - "deprecated and has no effect, because the proxy always exits " - "when database setup fails at startup. You can safely remove it.\033[0m", - ) + _print_enforce_prisma_migration_check_notice() # Handle database URL construction when no config file is used if config is None and os.getenv("DATABASE_URL") is None: # Use helper function to construct DATABASE_URL from individual variables diff --git a/tests/unit/proxy/test_proxy_cli.py b/tests/unit/proxy/test_proxy_cli.py index 4bb1426aaa0..5ecebe86e30 100644 --- a/tests/unit/proxy/test_proxy_cli.py +++ b/tests/unit/proxy/test_proxy_cli.py @@ -2872,6 +2872,22 @@ class TestRunServerDbSetup: mock_setup_database.assert_called_once_with(use_migrate=True, use_v2_resolver=True) assert ("--enforce_prisma_migration_check is deprecated and has no effect" in capsys.readouterr().out) is warned + @pytest.mark.parametrize("argument", ("--health", "--test"), ids=("health", "test")) + def test_the_retired_enforce_prisma_migration_check_opt_in_warns_on_health_and_test(self, argument, capsys): + """`--health` and `--test` return before the config is read, where a server start emits the + deprecation line; they still print it, as they did when the notice came before those returns.""" + from litellm.proxy.proxy_cli import ProxyInitializationHelpers, run_server + + with ( + patch.object(ProxyInitializationHelpers, "run_health_check") as mock_health_check, + patch.object(ProxyInitializationHelpers, "run_test_chat_completion") as mock_test_chat, + ): + run_server.main([argument, "--enforce_prisma_migration_check"], standalone_mode=False) + + expected_calls = (1, 0) if argument == "--health" else (0, 1) + assert (mock_health_check.call_count, mock_test_chat.call_count) == expected_calls + assert "--enforce_prisma_migration_check is deprecated and has no effect" in capsys.readouterr().out + @patch("subprocess.run") @patch("atexit.register") @patch("litellm.proxy.db.prisma_client.PrismaManager.setup_database", return_value=True)