jason810496 commented on code in PR #59753:
URL: https://github.com/apache/airflow/pull/59753#discussion_r2647510003
##########
providers/google/src/airflow/providers/google/cloud/log/gcs_task_handler.py:
##########
@@ -164,18 +183,29 @@ def read(self, relative_path: str, ti: RuntimeTI) ->
tuple[LogSourceInfo, LogMes
else:
messages.extend(["Found remote logs:", *[f" * {x}" for x in
sorted(uris)]])
else:
- return messages, None
+ return messages, []
try:
for key in sorted(uris):
blob = storage.Blob.from_string(key, self.client)
- remote_log = blob.download_as_bytes().decode()
- if remote_log:
- logs.append(remote_log)
+ stream = blob.open("r")
Review Comment:
I had tried the following before
```python
stream: TextIOWrapper # <-------
try:
for key in sorted(uris):
blob = storage.Blob.from_string(key, self.client)
stream = blob.open("r")
log_streams.append(self._get_log_stream(stream))
except Exception as e:
if not AIRFLOW_V_3_0_PLUS:
messages.append(f"Unable to read remote log {e}")
finally:
if not stream.closed: # <-------
stream.close()
return messages, log_streams
```
but it will result in `UnboundLocalError` error.
```python
providers/google/src/airflow/providers/google/cloud/log/gcs_task_handler.py:198:
in stream
if not stream.closed:
E UnboundLocalError: local variable 'stream' referenced before assignment
```
So unfortunately we are not able to add at finally block I think.
--
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]