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

jedcunningham 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 8fa2557dd1c Fix attribute error on accessing Gitbundle.repo_url 
(#46394)
8fa2557dd1c is described below

commit 8fa2557dd1cd5764da74f7f5d880606ad9a66e56
Author: Ephraim Anierobi <[email protected]>
AuthorDate: Tue Feb 4 01:00:20 2025 +0100

    Fix attribute error on accessing Gitbundle.repo_url (#46394)
    
    The position where we added the repo_url makes it unavailable
    on the GitBundle instance when the connection id is not defined.
    This PR fixes it and added a test to check that it has the attribute
    when the connection ID is not defined
    
    Co-authored-by: Jed Cunningham 
<[email protected]>
---
 airflow/dag_processing/bundles/git.py    |  5 +++--
 tests/dag_processing/test_dag_bundles.py | 11 +++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/airflow/dag_processing/bundles/git.py 
b/airflow/dag_processing/bundles/git.py
index 5d731ea7bc4..abebbb4a338 100644
--- a/airflow/dag_processing/bundles/git.py
+++ b/airflow/dag_processing/bundles/git.py
@@ -120,11 +120,12 @@ class GitDagBundle(BaseDagBundle, LoggingMixin):
             self._dag_bundle_root_storage_path / "git" / (self.name + 
f"+{self.version or self.tracking_ref}")
         )
         self.git_conn_id = git_conn_id
+        self.repo_url = repo_url
         try:
             self.hook = GitHook(git_conn_id=self.git_conn_id)
-            self.repo_url = repo_url or self.hook.repo_url
+            self.repo_url = self.repo_url or self.hook.repo_url
         except AirflowException as e:
-            self.log.error("Error creating GitHook: %s", e)
+            self.log.warning("Could not create GitHook for connection %s : 
%s", self.git_conn_id, e)
 
     def _initialize(self):
         self._clone_bare_repo_if_required()
diff --git a/tests/dag_processing/test_dag_bundles.py 
b/tests/dag_processing/test_dag_bundles.py
index 8926448f5ea..6ab1f3ea68f 100644
--- a/tests/dag_processing/test_dag_bundles.py
+++ b/tests/dag_processing/test_dag_bundles.py
@@ -506,3 +506,14 @@ class TestGitDagBundle:
                     bundle._clone_repo_if_required()
 
                 assert "Repository path: %s not found" in str(exc_info.value)
+
+    @mock.patch("airflow.dag_processing.bundles.git.GitDagBundle.log")
+    def test_repo_url_access_missing_connection_doesnt_error(self, mock_log):
+        bundle = GitDagBundle(
+            name="testa",
+            tracking_ref="main",
+            git_conn_id="unknown",
+            repo_url="some_repo_url",
+        )
+        assert bundle.repo_url == "some_repo_url"
+        assert "Could not create GitHook for connection" in 
mock_log.warning.call_args[0][0]

Reply via email to