kazanzhy commented on a change in pull request #20329:
URL: https://github.com/apache/airflow/pull/20329#discussion_r771879645
##########
File path: airflow/providers/google/cloud/operators/bigquery.py
##########
@@ -948,7 +948,10 @@ def execute(self, context) -> None:
delegate_to=self.delegate_to,
impersonation_chain=self.impersonation_chain,
)
- schema_fields = json.loads(gcs_hook.download(gcs_bucket,
gcs_object).decode("utf-8"))
+ schema_fields_bytes_or_string = gcs_hook.download(gcs_bucket,
gcs_object)
+ if hasattr(schema_fields_bytes_or_string, 'decode'):
+ schema_fields_bytes_or_string = cast(bytes,
schema_fields_bytes_or_string).decode("utf-8")
+ schema_fields = json.loads(schema_fields_bytes_or_string)
else:
Review comment:
I recently changed `gcs_hooks`'s return value as the solution to an
issue.
So if you are not passing the `filename` to the `download()` method it will
return only bytes otherwise file name.
Therefore the variable `schema_fields_bytes_or_string` always will be as
bytes, but unfortunately `gcs_hook.download`'s return type is `bytes | str`.
So how do you think could we skip this check `if
hasattr(schema_fields_bytes_or_string, 'decode')`?
Also, maybe we could use here something like that?
`gcs_hook.get_conn().bucket(gcs_bucket).blob(blob_name=gcs_object).download_as_bytes()`
--
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]