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

kaxilnaik pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new dd0efe348b6 Use 'git_default' if the user defines nothing (#49359)
dd0efe348b6 is described below

commit dd0efe348b6ce94243ec7a727f9aa908eeafbc82
Author: Tzu-ping Chung <[email protected]>
AuthorDate: Thu Apr 17 00:29:13 2025 +0800

    Use 'git_default' if the user defines nothing (#49359)
    
    * Use 'git_default' if the user defines nothing
    
    When using a GitDagBundle, the user should tell us where the git repo is
    by either repo_url or git_conn_id. If the user provides neither, try to
    find a Connection named 'git_default' instead of failing directly.
    
    If repo_url is provided, we won't try to find any Connection.
    
    * Revert "Fix failing git bundle tests (#49313)"
    
    This reverts commit 32b3f7cee6d3f3945b215b070c82341b31341c04.
    
    * Fix test
    
    ---------
    
    Co-authored-by: Kaxil Naik <[email protected]>
---
 .../core_api/routes/public/test_dag_versions.py    | 22 +++++++++++-----------
 .../core_api/routes/public/test_task_instances.py  |  6 +++---
 .../git/src/airflow/providers/git/bundles/git.py   |  9 ++++++---
 providers/git/tests/unit/git/bundles/test_git.py   |  4 +---
 4 files changed, 21 insertions(+), 20 deletions(-)

diff --git 
a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_versions.py
 
b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_versions.py
index ba87d6fe8c5..e3ad0d8bf64 100644
--- 
a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_versions.py
+++ 
b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_versions.py
@@ -56,7 +56,7 @@ class TestGetDagVersion(TestDagVersionEndpoint):
                 {
                     "bundle_name": "another_bundle_name",
                     "bundle_version": "some_commit_hash",
-                    "bundle_url": None,
+                    "bundle_url": 
"fakeprotocol://test_host.github.com/tree/some_commit_hash/dags",
                     "created_at": mock.ANY,
                     "dag_id": "ANOTHER_DAG_ID",
                     "id": mock.ANY,
@@ -69,7 +69,7 @@ class TestGetDagVersion(TestDagVersionEndpoint):
                 {
                     "bundle_name": "dag_maker",
                     "bundle_version": "some_commit_hash1",
-                    "bundle_url": None,
+                    "bundle_url": 
"fakeprotocol://test_host.github.com/tree/some_commit_hash1/dags",
                     "created_at": mock.ANY,
                     "dag_id": "dag_with_multiple_versions",
                     "id": mock.ANY,
@@ -82,7 +82,7 @@ class TestGetDagVersion(TestDagVersionEndpoint):
                 {
                     "bundle_name": "dag_maker",
                     "bundle_version": "some_commit_hash2",
-                    "bundle_url": None,
+                    "bundle_url": 
"fakeprotocol://test_host.github.com/tree/some_commit_hash2/dags",
                     "created_at": mock.ANY,
                     "dag_id": "dag_with_multiple_versions",
                     "id": mock.ANY,
@@ -95,7 +95,7 @@ class TestGetDagVersion(TestDagVersionEndpoint):
                 {
                     "bundle_name": "dag_maker",
                     "bundle_version": "some_commit_hash3",
-                    "bundle_url": None,
+                    "bundle_url": 
"fakeprotocol://test_host.github.com/tree/some_commit_hash3/dags",
                     "created_at": mock.ANY,
                     "dag_id": "dag_with_multiple_versions",
                     "id": mock.ANY,
@@ -139,7 +139,7 @@ class TestGetDagVersions(TestDagVersionEndpoint):
                         {
                             "bundle_name": "another_bundle_name",
                             "bundle_version": "some_commit_hash",
-                            "bundle_url": None,
+                            "bundle_url": 
"fakeprotocol://test_host.github.com/tree/some_commit_hash/dags",
                             "created_at": mock.ANY,
                             "dag_id": "ANOTHER_DAG_ID",
                             "id": mock.ANY,
@@ -148,7 +148,7 @@ class TestGetDagVersions(TestDagVersionEndpoint):
                         {
                             "bundle_name": "dag_maker",
                             "bundle_version": "some_commit_hash1",
-                            "bundle_url": None,
+                            "bundle_url": 
"fakeprotocol://test_host.github.com/tree/some_commit_hash1/dags",
                             "created_at": mock.ANY,
                             "dag_id": "dag_with_multiple_versions",
                             "id": mock.ANY,
@@ -157,7 +157,7 @@ class TestGetDagVersions(TestDagVersionEndpoint):
                         {
                             "bundle_name": "dag_maker",
                             "bundle_version": "some_commit_hash2",
-                            "bundle_url": None,
+                            "bundle_url": 
"fakeprotocol://test_host.github.com/tree/some_commit_hash2/dags",
                             "created_at": mock.ANY,
                             "dag_id": "dag_with_multiple_versions",
                             "id": mock.ANY,
@@ -166,7 +166,7 @@ class TestGetDagVersions(TestDagVersionEndpoint):
                         {
                             "bundle_name": "dag_maker",
                             "bundle_version": "some_commit_hash3",
-                            "bundle_url": None,
+                            "bundle_url": 
"fakeprotocol://test_host.github.com/tree/some_commit_hash3/dags",
                             "created_at": mock.ANY,
                             "dag_id": "dag_with_multiple_versions",
                             "id": mock.ANY,
@@ -183,7 +183,7 @@ class TestGetDagVersions(TestDagVersionEndpoint):
                         {
                             "bundle_name": "dag_maker",
                             "bundle_version": "some_commit_hash1",
-                            "bundle_url": None,
+                            "bundle_url": 
"fakeprotocol://test_host.github.com/tree/some_commit_hash1/dags",
                             "created_at": mock.ANY,
                             "dag_id": "dag_with_multiple_versions",
                             "id": mock.ANY,
@@ -192,7 +192,7 @@ class TestGetDagVersions(TestDagVersionEndpoint):
                         {
                             "bundle_name": "dag_maker",
                             "bundle_version": "some_commit_hash2",
-                            "bundle_url": None,
+                            "bundle_url": 
"fakeprotocol://test_host.github.com/tree/some_commit_hash2/dags",
                             "created_at": mock.ANY,
                             "dag_id": "dag_with_multiple_versions",
                             "id": mock.ANY,
@@ -201,7 +201,7 @@ class TestGetDagVersions(TestDagVersionEndpoint):
                         {
                             "bundle_name": "dag_maker",
                             "bundle_version": "some_commit_hash3",
-                            "bundle_url": None,
+                            "bundle_url": 
"fakeprotocol://test_host.github.com/tree/some_commit_hash3/dags",
                             "created_at": mock.ANY,
                             "dag_id": "dag_with_multiple_versions",
                             "id": mock.ANY,
diff --git 
a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_task_instances.py
 
b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_task_instances.py
index 3211ca33f63..562a254c50f 100644
--- 
a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_task_instances.py
+++ 
b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_task_instances.py
@@ -274,7 +274,7 @@ class TestGetTaskInstance(TestTaskInstanceEndpoint):
                 "dag_id": "dag_with_multiple_versions",
                 "bundle_name": "dag_maker",
                 "bundle_version": f"some_commit_hash{expected_version_number}",
-                "bundle_url": None,
+                "bundle_url": 
f"fakeprotocol://test_host.github.com/tree/some_commit_hash{expected_version_number}/dags",
                 "created_at": mock.ANY,
             },
         }
@@ -1961,7 +1961,7 @@ class TestGetTaskInstanceTry(TestTaskInstanceEndpoint):
                 "dag_id": "dag_with_multiple_versions",
                 "bundle_name": "dag_maker",
                 "bundle_version": f"some_commit_hash{expected_version_number}",
-                "bundle_url": None,
+                "bundle_url": 
f"fakeprotocol://test_host.github.com/tree/some_commit_hash{expected_version_number}/dags",
                 "created_at": mock.ANY,
             },
         }
@@ -3023,7 +3023,7 @@ class TestGetTaskInstanceTries(TestTaskInstanceEndpoint):
                 "dag_id": "dag_with_multiple_versions",
                 "bundle_name": "dag_maker",
                 "bundle_version": f"some_commit_hash{expected_version_number}",
-                "bundle_url": None,
+                "bundle_url": 
f"fakeprotocol://test_host.github.com/tree/some_commit_hash{expected_version_number}/dags",
                 "created_at": mock.ANY,
             },
         }
diff --git a/providers/git/src/airflow/providers/git/bundles/git.py 
b/providers/git/src/airflow/providers/git/bundles/git.py
index 7180e04b50a..1b4084f1db2 100644
--- a/providers/git/src/airflow/providers/git/bundles/git.py
+++ b/providers/git/src/airflow/providers/git/bundles/git.py
@@ -80,11 +80,14 @@ class GitDagBundle(BaseDagBundle):
 
         self._log.debug("bundle configured")
         self.hook: GitHook | None = None
-        if self.git_conn_id:
+        if not repo_url:
+            if not git_conn_id:
+                self._log.debug("Neither git_conn_id nor repo_url provided; 
loading 'git_default'")
+                git_conn_id = "git_default"
             try:
-                self.hook = GitHook(git_conn_id=self.git_conn_id, 
repo_url=self.repo_url)
+                self.hook = GitHook(git_conn_id=git_conn_id)
             except AirflowException as e:
-                self._log.warning("Could not create GitHook", 
conn_id=self.git_conn_id, exc=e)
+                self._log.warning("Could not create GitHook", 
conn_id=git_conn_id, exc=e)
             else:
                 self.repo_url = self.hook.repo_url
                 self._log.debug("repo_url updated from hook")
diff --git a/providers/git/tests/unit/git/bundles/test_git.py 
b/providers/git/tests/unit/git/bundles/test_git.py
index 776af12989a..bac3cdb39c1 100644
--- a/providers/git/tests/unit/git/bundles/test_git.py
+++ b/providers/git/tests/unit/git/bundles/test_git.py
@@ -116,7 +116,7 @@ class TestGitDagBundle:
             tracking_ref=GIT_DEFAULT_BRANCH,
             repo_url="https://github.com/apache/zzzairflow";,
         )
-        assert bundle.repo_url == 
f"https://{ACCESS_TOKEN}@github.com/apache/zzzairflow";
+        assert bundle.repo_url == "https://github.com/apache/zzzairflow";
 
     def test_falls_back_to_connection_host_when_no_repo_url_provided(self):
         bundle = GitDagBundle(name="test", git_conn_id=CONN_HTTPS, 
tracking_ref=GIT_DEFAULT_BRANCH)
@@ -564,9 +564,7 @@ class TestGitDagBundle:
             name="testa",
             tracking_ref="main",
             git_conn_id=conn_id,
-            repo_url="some_repo_url",
         )
-        assert bundle.repo_url == "some_repo_url"
         assert isinstance(bundle.hook, expected_hook_type)
 
     @mock.patch("airflow.providers.git.bundles.git.GitHook")

Reply via email to