Fix DockerOperator xcom - #9464
Conversation
|
@mik-laj @akki I closed accidentally the other PR. Then I cleaned up things and put on this new. Can you review It again? About your questions: I added the example on The reviews about I decided to keep the warnings together with stdout on airflow logs, but save only stdout on xcom to solve the issue 3. The |
2c1281b to
9e48292
Compare
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
I'm not having enough time to update It, but I still want to merge this PR, on the following month I'll try to resolve conflicts and ask for reviews again. Please don't close this PR yet. |
|
Hey @nullhack can you rebase, please? In the meantime we introduced black formatter in providers packages :) |
Yes, I'll do soon |
3acd1ba to
9cdb031
Compare
|
Hey @nullhack the test are failing, can you take a look? |
|
@turbaszek I couldn't find failing tests related to this PR, I just assumed they are long time failing tests like others I did. For example |
|
@nullhack I think in all cases TestDockerOperator.test_execute_xcom_behavior is failing |
Yes: |
|
Thank you, yes you're right. They're failing because the test assume a binary string One of the modifications of this PR is changing this to a decoded string instead (to have same output type as bash operator and make It easier to use the xcom results from other operators). At this point I have three options
Which one should I go for? |
|
Ok, I'll change the code then to include deprecation warning and the new flag with default value as binary |
akki
left a comment
There was a problem hiding this comment.
Please have a look at the generator part. Check if using yield makes more sense to you as well.
|
|
||
| self.cli.start(self.container['Id']) | ||
| def gen_output(stdout=False, stderr=False): | ||
| return ( |
There was a problem hiding this comment.
Hi
I don't think using a generator instead of a list here solves the memory issue. The data will in the end be kept in memory - no matter you use a list or a generator.
I did a small test to verify this; I ran the following code in a Python3 terminal:
>>> with open('yes.log', 'r') as file_:
... x = (linee for linee in file_.read())
...
where yes.log was a 650 MB file.
As soon as the execution of this code-block completed, I saw the memory used by this process increase by 650 MB. It makes sense as well because where else would generators be storing these logs if not in memory.
I am thinking that you might be able to achieve what you're trying to do by streaming the logs and using yield.
There was a problem hiding this comment.
Thank you for the feedback Akki. I'll make some tests during this week and see if I can solve this using yield and streaming.
|
Sorry, I'm not having time to work on this and probably will not be able to do for a while. I'll close the PR to give the chance of other people to work on this. Anyone feel free to fork my repo and continue |

This PR solves the issue #9164
This PR continues the discussion of #9165
Files changed:
airflow/providers/docker/operators/docker.pyairflow/providers/docker/example_dags/example_docker_xcom.pyProblems
xcom_push=Trueis enabled (andxcom_push_all=False), the output sometimes is null OR captured wrongly.xcom_push_all=Truea bytes string (b'...') is stored as xcom, It's harder to use the output on following operators and is not compliant with other operators.Stderrandstdoutare written to the same output xcom. In practice, we don't want warnings and errors messing up with the code to be parsed on following operators (But we need to capture the output on airflow logs). Sendingstderrto xcom can lead to undefined/non-deterministic behavior.Solutions:
... templ.decode("utf-8").strip() if hasattr(templ, "decode") else str(templ) ...stdoutinto xcom:In the end, only logs are send to xcom and if any error is raised, the DAG run fail after finishing:
Sample Output
We would expect only the last line '9'Issue 2:
Issue 3:
Stderrdo not mess up with the output and has deterministic behaviorunnecessaryunnecessary