-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle some git exceptions when initializing GitDagBundle (#46253)
* Handle some git exceptions when initializing GitDagBundle Permission error raises GitCommandError, and if the cloned path is manually removed, it will result in a path not found error when cloning from the bare repo path * Apply suggestions from code review Co-authored-by: Jed Cunningham <[email protected]> * fixup! Apply suggestions from code review * Fix comment * Update airflow/dag_processing/bundles/git.py Co-authored-by: Jed Cunningham <[email protected]> * fix test --------- Co-authored-by: Jed Cunningham <[email protected]>
- Loading branch information
1 parent
8a3757b
commit ef66a9f
Showing
2 changed files
with
47 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,14 @@ | |
|
||
from __future__ import annotations | ||
|
||
import re | ||
import tempfile | ||
from pathlib import Path | ||
from unittest import mock | ||
|
||
import pytest | ||
from git import Repo | ||
from git.exc import GitCommandError, NoSuchPathError | ||
|
||
from airflow.dag_processing.bundles.base import BaseDagBundle | ||
from airflow.dag_processing.bundles.git import GitDagBundle, GitHook | ||
|
@@ -477,3 +479,30 @@ def test_view_url_returns_none_when_no_version_in_view_url(self, mock_gitrepo): | |
) | ||
view_url = bundle.view_url(None) | ||
assert view_url is None | ||
|
||
@mock.patch("airflow.dag_processing.bundles.git.GitHook") | ||
def test_clone_bare_repo_git_command_error(self, mock_githook): | ||
mock_githook.return_value.repo_url = "[email protected]:apache/airflow.git" | ||
mock_githook.return_value.env = {} | ||
|
||
with mock.patch("airflow.dag_processing.bundles.git.Repo.clone_from") as mock_clone: | ||
mock_clone.side_effect = GitCommandError("clone", "Simulated error") | ||
bundle = GitDagBundle(name="test", tracking_ref="main") | ||
with pytest.raises( | ||
AirflowException, | ||
match=re.escape("Error cloning repository"), | ||
): | ||
bundle.initialize() | ||
|
||
@mock.patch("airflow.dag_processing.bundles.git.GitHook") | ||
def test_clone_repo_no_such_path_error(self, mock_githook): | ||
mock_githook.return_value.repo_url = "[email protected]:apache/airflow.git" | ||
|
||
with mock.patch("airflow.dag_processing.bundles.git.os.path.exists", return_value=False): | ||
with mock.patch("airflow.dag_processing.bundles.git.Repo.clone_from") as mock_clone: | ||
mock_clone.side_effect = NoSuchPathError("Path not found") | ||
bundle = GitDagBundle(name="test", tracking_ref="main") | ||
with pytest.raises(AirflowException) as exc_info: | ||
bundle._clone_repo_if_required() | ||
|
||
assert "Repository path: %s not found" in str(exc_info.value) |