Skip to content
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

Merged
merged 2 commits into from
Jul 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion airflow/operators/docker_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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 :)

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaxil @mik-laj So would you like to see any changes in this PR or does it have your approval?

Copy link
Member

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.

commands = ast.literal_eval(self.command)
else:
commands = self.command
Expand Down