You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by je...@apache.org on 2025/02/13 01:29:01 UTC

(airflow) branch main updated: Remove validation on git dag bundle repo_url (#46705)

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 77d88fb1f46 Remove validation on git dag bundle repo_url (#46705)
77d88fb1f46 is described below

commit 77d88fb1f46ca3ae8bc5f2bae8fc255a98ceb723
Author: Jed Cunningham <66...@users.noreply.github.com>
AuthorDate: Wed Feb 12 18:28:55 2025 -0700

    Remove validation on git dag bundle repo_url (#46705)
    
    We should be flexible with what repo_urls we accept. Git will tell us if
    it isn't able to get to the repo after all.
    
    This does have an impact on `view_url`, but that was already correct for
    the common cases, so I've simply expanded test coverage a bit.
---
 airflow/dag_processing/bundles/git.py    | 11 +----------
 tests/dag_processing/bundles/test_git.py | 29 +++++++----------------------
 2 files changed, 8 insertions(+), 32 deletions(-)

diff --git a/airflow/dag_processing/bundles/git.py b/airflow/dag_processing/bundles/git.py
index ea6833e66ba..8855a73a1d5 100644
--- a/airflow/dag_processing/bundles/git.py
+++ b/airflow/dag_processing/bundles/git.py
@@ -172,16 +172,7 @@ class GitDagBundle(BaseDagBundle, LoggingMixin):
     def initialize(self) -> None:
         if not self.repo_url:
             raise AirflowException(f"Connection {self.git_conn_id} doesn't have a host url")
-        if isinstance(self.repo_url, os.PathLike):
-            self._initialize()
-        elif not (
-            self.repo_url.startswith("git@") or self.repo_url.startswith("https")
-        ) or not self.repo_url.endswith(".git"):
-            raise AirflowException(
-                f"Invalid git URL: {self.repo_url}. URL must start with git@ or https and end with .git"
-            )
-        else:
-            self._initialize()
+        self._initialize()
         super().initialize()
 
     def _clone_repo_if_required(self) -> None:
diff --git a/tests/dag_processing/bundles/test_git.py b/tests/dag_processing/bundles/test_git.py
index 29f3c423b77..a2abbf0c590 100644
--- a/tests/dag_processing/bundles/test_git.py
+++ b/tests/dag_processing/bundles/test_git.py
@@ -436,32 +436,13 @@ class TestGitDagBundle:
         # check remotes called twice. one at initialize and one at refresh above
         assert mock_gitRepo.return_value.remotes.origin.fetch.call_count == 2
 
-    @pytest.mark.parametrize(
-        "repo_url",
-        [
-            pytest.param("https://github.com/apache/airflow", id="https_url"),
-            pytest.param("airflow@example:apache/airflow.git", id="does_not_start_with_git_at"),
-            pytest.param("git@example:apache/airflow", id="does_not_end_with_dot_git"),
-        ],
-    )
-    @mock.patch("airflow.dag_processing.bundles.git.GitHook")
-    def test_repo_url_validation_for_ssh(self, mock_hook, repo_url, session):
-        mock_hook.return_value.repo_url = repo_url
-        bundle = GitDagBundle(
-            name="test",
-            git_conn_id="git_default",
-            tracking_ref=GIT_DEFAULT_BRANCH,
-        )
-        with pytest.raises(
-            AirflowException,
-            match=f"Invalid git URL: {repo_url}. URL must start with git@ or https and end with .git",
-        ):
-            bundle.initialize()
-
     @pytest.mark.parametrize(
         "repo_url, expected_url",
         [
             ("git@github.com:apache/airflow.git", "https://github.com/apache/airflow/tree/0f0f0f"),
+            ("git@github.com:apache/airflow", "https://github.com/apache/airflow/tree/0f0f0f"),
+            ("https://github.com/apache/airflow", "https://github.com/apache/airflow/tree/0f0f0f"),
+            ("https://github.com/apache/airflow.git", "https://github.com/apache/airflow/tree/0f0f0f"),
             ("git@gitlab.com:apache/airflow.git", "https://gitlab.com/apache/airflow/-/tree/0f0f0f"),
             ("git@bitbucket.org:apache/airflow.git", "https://bitbucket.org/apache/airflow/src/0f0f0f"),
             (
@@ -472,6 +453,8 @@ class TestGitDagBundle:
                 "https://myorg.github.com/apache/airflow.git",
                 "https://myorg.github.com/apache/airflow/tree/0f0f0f",
             ),
+            ("/dev/null", None),
+            ("file:///dev/null", None),
         ],
     )
     @mock.patch("airflow.dag_processing.bundles.git.Repo")
@@ -488,8 +471,10 @@ class TestGitDagBundle:
             name="test",
             tracking_ref="main",
         )
+        bundle.initialize = mock.MagicMock()
         view_url = bundle.view_url("0f0f0f")
         assert view_url == expected_url
+        bundle.initialize.assert_not_called()
 
     @mock.patch("airflow.dag_processing.bundles.git.Repo")
     def test_view_url_returns_none_when_no_version_in_view_url(self, mock_gitrepo):