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

potiuk 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 b2825e1185 Fix GoogleDriveHook writing files to trashed folders on 
upload v2 (#29119)
b2825e1185 is described below

commit b2825e11852890cf0b0f4d0bcaae592311781cdf
Author: Victor Chiapaikeo <vchiapai...@gmail.com>
AuthorDate: Tue Jan 24 10:25:01 2023 -0500

    Fix GoogleDriveHook writing files to trashed folders on upload v2 (#29119)
---
 airflow/providers/google/suite/hooks/drive.py    |  3 +-
 tests/providers/google/suite/hooks/test_drive.py | 42 ++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/airflow/providers/google/suite/hooks/drive.py 
b/airflow/providers/google/suite/hooks/drive.py
index 9e3b4a5437..abfae6201b 100644
--- a/airflow/providers/google/suite/hooks/drive.py
+++ b/airflow/providers/google/suite/hooks/drive.py
@@ -81,7 +81,8 @@ class GoogleDriveHook(GoogleBaseHook):
         for current_folder in folders:
             self.log.debug("Looking for %s directory with %s parent", 
current_folder, current_parent)
             conditions = [
-                "mimeType = 'application/vnd.google-apps.folder'",
+                "trashed=false",
+                "mimeType='application/vnd.google-apps.folder'",
                 f"name='{current_folder}'",
                 f"'{current_parent}' in parents",
             ]
diff --git a/tests/providers/google/suite/hooks/test_drive.py 
b/tests/providers/google/suite/hooks/test_drive.py
index 4dfddaa8de..7670b270ec 100644
--- a/tests/providers/google/suite/hooks/test_drive.py
+++ b/tests/providers/google/suite/hooks/test_drive.py
@@ -57,6 +57,16 @@ class TestGoogleDriveHook:
 
         mock_get_conn.assert_has_calls(
             [
+                mock.call()
+                .files()
+                .list(
+                    q=(
+                        "trashed=false and 
mimeType='application/vnd.google-apps.folder' "
+                        "and name='AAA' and 'root' in parents"
+                    ),
+                    spaces="drive",
+                    fields="files(id, name)",
+                ),
                 mock.call()
                 .files()
                 .create(
@@ -119,6 +129,19 @@ class TestGoogleDriveHook:
 
         mock_get_conn.assert_has_calls(
             [
+                *[
+                    mock.call()
+                    .files()
+                    .list(
+                        q=(
+                            "trashed=false and 
mimeType='application/vnd.google-apps.folder' "
+                            f"and name='{d}' and '{key}' in parents"
+                        ),
+                        spaces="drive",
+                        fields="files(id, name)",
+                    )
+                    for d, key in [("AAA", "root"), ("BBB", "ID_1"), ("CCC", 
"ID_2")]
+                ],
                 mock.call()
                 .files()
                 .create(
@@ -156,6 +179,25 @@ class TestGoogleDriveHook:
 
         result_value = 
self.gdrive_hook._ensure_folders_exists("AAA/BBB/CCC/DDD")
 
+        mock_get_conn.assert_has_calls(
+            [
+                *[
+                    mock.call()
+                    .files()
+                    .list(
+                        q=(
+                            "trashed=false and 
mimeType='application/vnd.google-apps.folder' "
+                            f"and name='{d}' and '{key}' in parents"
+                        ),
+                        spaces="drive",
+                        fields="files(id, name)",
+                    )
+                    for d, key in [("AAA", "root"), ("BBB", "ID_1"), ("CCC", 
"ID_2"), ("DDD", "ID_3")]
+                ],
+            ],
+            any_order=True,
+        )
+
         
mock_get_conn.return_value.files.return_value.create.assert_not_called()
         assert "ID_4" == result_value
 

Reply via email to