You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ra...@apache.org on 2026/07/31 11:49:54 UTC

(airflow) branch v3-3-test updated: [v3-3-test] cli: Fix TypeError in 'airflow db shell' when database name is missing (#68913) (#70752)

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

vatsrahul1001 pushed a commit to branch v3-3-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v3-3-test by this push:
     new 927f78bf72b [v3-3-test] cli: Fix TypeError in 'airflow db shell' when database name is missing (#68913) (#70752)
927f78bf72b is described below

commit 927f78bf72bbb0649e8a6fb0c42dda005d775589
Author: github-actions[bot] <41...@users.noreply.github.com>
AuthorDate: Fri Jul 31 17:19:47 2026 +0530

    [v3-3-test] cli: Fix TypeError in 'airflow db shell' when database name is missing (#68913) (#70752)
    
    (cherry picked from commit 521ad026ee46fef7ed0241b6a462e71ca151edf5)
    
    Co-authored-by: Sejal Gupta <se...@ksolves.com>
    Co-authored-by: Rahul Vats <43...@users.noreply.github.com>
---
 airflow-core/src/airflow/cli/commands/db_command.py     |  6 ++++++
 airflow-core/tests/unit/cli/commands/test_db_command.py | 17 +++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/airflow-core/src/airflow/cli/commands/db_command.py b/airflow-core/src/airflow/cli/commands/db_command.py
index 4c15ccc2d48..54de07299c6 100644
--- a/airflow-core/src/airflow/cli/commands/db_command.py
+++ b/airflow-core/src/airflow/cli/commands/db_command.py
@@ -306,6 +306,12 @@ def shell(args):
     url = settings.get_engine().url
     print(f"DB: {url!r}")
 
+    if not url.database:
+        raise ValueError(
+            "The metadata database name is missing from the connection URI. "
+            "Please check your AIRFLOW__DATABASE__SQL_ALCHEMY_CONN configuration."
+        )
+
     if url.get_backend_name() == "mysql":
         with NamedTemporaryFile(suffix="my.cnf") as f:
             f.write(_build_mysql_cnf(url))
diff --git a/airflow-core/tests/unit/cli/commands/test_db_command.py b/airflow-core/tests/unit/cli/commands/test_db_command.py
index 76e391e1144..e6168605a3f 100644
--- a/airflow-core/tests/unit/cli/commands/test_db_command.py
+++ b/airflow-core/tests/unit/cli/commands/test_db_command.py
@@ -534,6 +534,23 @@ class TestCliDb:
         with pytest.raises(AirflowException, match=r"Unknown driver: invalid\+psycopg"):
             db_command.shell(self.parser.parse_args(["db", "shell"]))
 
+    @mock.patch(
+        "airflow.cli.commands.db_command.settings.engine.url",
+        make_url("postgresql+psycopg2://postgres:airflow@postgres/"),
+    )
+    @pytest.mark.parametrize(
+        "conn_uri",
+        [
+            pytest.param("postgresql://postgres:postgres@postgres:5432", id="db-name-none"),
+            pytest.param("postgresql://postgres:postgres@postgres:5432/", id="db-name-empty"),
+        ],
+    )
+    def test_db_shell_missing_database_name(self, conn_uri):
+        """Assert that an explicit ValueError is raised when the database name is missing."""
+        with mock.patch("airflow.cli.commands.db_command.settings.engine.url", make_url(conn_uri)):
+            with pytest.raises(ValueError, match="The metadata database name is missing"):
+                db_command.shell(self.parser.parse_args(["db", "shell"]))
+
     def test_run_db_downgrade_command_success_and_messages(self, capsys):
         class Args:
             to_revision = "abc"