-
Notifications
You must be signed in to change notification settings - Fork 14.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AIRFLOW-4763] Allow list in DockerOperator.command #5408
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5408 +/- ##
=========================================
Coverage ? 79.13%
=========================================
Files ? 488
Lines ? 30608
Branches ? 0
=========================================
Hits ? 24222
Misses ? 6386
Partials ? 0
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of..
def get_command(self):
if self.command is not None and isinstance(self.command, str) and self.command.strip().find('[') == 0:
commands = ast.literal_eval(self.command)
else:
commands = self.command
Also see this why I used isinstance
instead of type
.
@feluelle Ahh, good point - just realised the redundancy. But I also see that the def get_command(self):
if isinstance(self.command, str) and self.command.strip().find('[') == 0:
commands = ast.literal_eval(self.command)
else:
commands = self.command Please have a look and let me know if you see any concerns. Thanks for the review. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@feluelle Thanks for the approval. I just wanted to confirm that this PR is not waiting for any action from my side. |
@@ -247,7 +247,7 @@ def execute(self, context): | |||
if self.xcom_all else line.encode('utf-8') | |||
|
|||
def get_command(self): | |||
if self.command is not None and self.command.strip().find('[') == 0: | |||
if isinstance(self.command, str) and self.command.strip().find('[') == 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have this and self.command.strip().find('[') == 0
?
Just trying to understand the logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When Jinja returns the "[" sign, an array is created. Please look at related PR: https://github.com//pull/4900
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jinja would convert a list to list. self.command.strip().find('[') == 0
is checking a string, right? and checking if the first character is [
.
Sorry, maybe I am missing something. @mik-laj Feel free to merge this PR :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a string is encountered, but the string looks like it contains arrays (starts with the character "[") it is processed by literal_parse, which creates the real table from the string.
>>> import ast
>>> ast.literal_eval('["A", "B"]')
['A', 'B']
>>>
Currently, Jinja always accepts a string at the input and returns a string. However, the mentioned PR discussed an alternative solution to the one used in this PR.
I can not do it at the moment. I just wanted to answer your question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @mik-laj for the explanation. I understand it now.
Hi, does anyone have any suggestion for this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thank you @akki for your contribution and apologies for having to wait this long. |
Ran into this bug on my very first custom DAG after going through the tutorials 😣 thanks @akki 👏 FWIW here's my monkeypatch workaround (until the better fix in this PR is released... from functools import partialmethod
from airflow.operators.docker_operator import DockerOperator
def get_command(operator):
return operator.command # assumes command is already a proper list
DockerOperator.get_command = partialmethod(get_command) |
(cherry picked from commit 2b94600)
https://issues.apache.org/jira/browse/AIRFLOW-4763 - in case the issue seems valid to the maintainers, here is the fix.
Make sure you have checked all steps below.
Jira
Description
Tests
Commits
Documentation
Code Quality
flake8