Fix returning last log line in docker operator#13793
Conversation
Iterable values in `cli.attach(..., stream=True)` are not necessarily single lines. Lines can be merged together or split because of buffering. When this split happens just before the last newline character, the returned value of `execute` is an empty byte string.
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst)
|
|
Related, but different issue: #13536 (converts return type to I believe |
| if self.do_xcom_push: | ||
| ret = self.cli.logs(container=self.container['Id']) if self.xcom_all else line.encode('utf-8') | ||
| if self.xcom_all: | ||
| ret = self.cli.logs(container=self.container['Id']) |
There was a problem hiding this comment.
I agree it should probably be stripped, but my intention was to keep the current behavior when do_xcom_push and xcom_all are all true.
| return ret | ||
|
|
||
| def execute(self, context) -> Optional[str]: | ||
| def execute(self, context) -> Optional[bytes]: |
There was a problem hiding this comment.
should we perhaps decode utf-8 (assuming that's what comes out of logs, so that we return a string type? sincere question... 🤔
There was a problem hiding this comment.
coincidence someone is doing exactly that: https://github.com/apache/airflow/pull/13536/files
There was a problem hiding this comment.
Yes, and I think this would make more sense, but again I wanted to avoid a breaking change...
I would actually be happy with this other PR being merged, as it now includes the fix in my PR.
|
@dstandish Thanks for your review. If #13536 gets merged, this one can be closed. I would personally consider this PR a bug fix, and #13536 a breaking change. |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions. |
Iterable values in
cli.attach(..., stream=True)are not necessarily single lines.Lines can be merged together or split because of buffering.
When this split happens just before the last newline character, the returned value of
executeis an empty byte string.Also, fix the return type annotation (the return type is not changed, only the annotation).
I used these files to recreate the issue:
Dockerfilemain.pyscript.pyWhen running:
$ docker build -t docker-bug . $ python script.pyThe output will look something like: