🔧 Suggestion / Hook Improvement: GoogleDriveHook.get_file_id #56487
Unanswered
JhonGarcia0
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi team! I'm new around this channel, but I've been using Apache Airflow for quite some time now. Today I ran into an issue that drove me a bit crazy, and I wanted to share a suggestion that might improve the developer experience and functionality of the GoogleDriveHook, specifically the get_file_id method in:
airflow.providers.google.suite.hooks.drive
When using a service account to search for files, I was unable to find a file that I knew existed. After digging for quite a while, I discovered two small (but important) behaviors that caused the issue.
Current code:
This syntax caused my service account to never find the file, even though it had access. After trying different formats and reviewing the Drive API documentation, I realized the correct (and working) format is:
This small change resolved the issue immediately. While subtle, the order in the query clause is critical when searching by parent folders.
Another issue arises when searching for files that are shared with the service account, but not in the service account's personal Drive or a shared drive (i.e., "Shared with me").
Currently, the code does:
But this only searches within the user's personal Drive (or within a shared drive if explicitly passed). However, when files are shared directly with the service account (without a driveId), they are not found by default.
To support this use case, I propose adding a new flag — for example,
shared_folder
, or another clearly named parameter — to explicitly enable searching in shared folders (i.e., files shared with the service account but not located in its own Drive or in a specific shared drive).When this flag is set to
True
, the following parameters should be included in thefiles().list()
call to ensure the Drive API can search across all available drives:This enhancement would make the hook more robust and flexible, especially for users relying on service accounts accessing files shared from external sources.
Thank you for your attention, and I hope this suggestion can be taken into consideration.
If you need any additional information or clarification, I’m happy to help and available to answer any questions this might raise.
Beta Was this translation helpful? Give feedback.
All reactions