Crowiant commented on code in PR #66929:
URL: https://github.com/apache/airflow/pull/66929#discussion_r3267238785
##########
providers/google/src/airflow/providers/google/suite/operators/sheets.py:
##########
@@ -65,14 +70,42 @@ def __init__(
self.spreadsheet = spreadsheet
self.impersonation_chain = impersonation_chain
self.api_endpoint = api_endpoint
+ self.drive_id = drive_id
def execute(self, context: Any) -> dict[str, Any]:
+ if self.drive_id:
+ spreadsheet = self._create_spreadsheet_via_google_drive_api()
+ else:
+ spreadsheet = self._create_spreadsheet_via_sheets_api()
+ context["task_instance"].xcom_push(key="spreadsheet_id",
value=spreadsheet["spreadsheetId"])
+ context["task_instance"].xcom_push(key="spreadsheet_url",
value=spreadsheet["spreadsheetUrl"])
+ return spreadsheet
+
+ def _construct_spreadsheet_metadata(self, spreadsheet) -> dict:
+ return {
+ "name": spreadsheet["properties"]["title"],
+ "mimeType": "application/vnd.google-apps.spreadsheet",
+ "parents": [self.drive_id],
Review Comment:
Could you please expand on this? My thoughts were that if in future
something change in the metadata construction or there will be new request from
users for constructing metadata differently we just change this function. Also,
there is no possibility to set parents None.
##########
providers/google/src/airflow/providers/google/suite/operators/sheets.py:
##########
@@ -65,14 +70,42 @@ def __init__(
self.spreadsheet = spreadsheet
self.impersonation_chain = impersonation_chain
self.api_endpoint = api_endpoint
+ self.drive_id = drive_id
def execute(self, context: Any) -> dict[str, Any]:
+ if self.drive_id:
+ spreadsheet = self._create_spreadsheet_via_google_drive_api()
+ else:
+ spreadsheet = self._create_spreadsheet_via_sheets_api()
+ context["task_instance"].xcom_push(key="spreadsheet_id",
value=spreadsheet["spreadsheetId"])
+ context["task_instance"].xcom_push(key="spreadsheet_url",
value=spreadsheet["spreadsheetUrl"])
+ return spreadsheet
+
+ def _construct_spreadsheet_metadata(self, spreadsheet) -> dict:
+ return {
+ "name": spreadsheet["properties"]["title"],
+ "mimeType": "application/vnd.google-apps.spreadsheet",
+ "parents": [self.drive_id],
+ }
+
+ def _create_spreadsheet_via_google_drive_api(self) -> dict:
Review Comment:
Renamed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]