-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Add Legacy command displaying new CLI counterparts #10115
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
Conversation
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.
How about
def check_value(action, value):
cmd_map = {
"worker": "celery worker", # old: new
...
}
try:
msg = "{} command, has been removed, please use `airflow {}`.format(value, cmd_map[value])
raise ArgumentError(action, msg)
except KeyError:
pass We can consider making this map a global constant as it may be useful in the future. WDYT?
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.
I like this!
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.
Yeah!
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.
How do you suggest to write a test for this? @turbaszek
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.
I would mock COMMAND_MAP with {"old_cmd": "new_cmd"} and then:
action = MagicMock()
with self.assertrises(ArgumentError):
check_value(action, "old_cmd")plus some regex check that the error msg is valid one.
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.
class TestCliDeprecatedCommandsValue(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.parser = cli_parser.get_parser()
def test_should_display_value(self):
with self.assertRaises(SystemExit) as cm_exception, \
contextlib.redirect_stderr(io.StringIO()) as temp_stderr:
config_command.get_value(self.parser.parse_args(['worker']))
self.assertEqual(2, cm_exception.exception.code)
self.assertIn(
"`airflow worker` command, has been removed, "
"please use `airflow celery worker`, see help above.",
temp_stderr.getvalue().strip()
)I propose to test this by testing the CLI parser. We overwrite private methods, so I wouldn't trust unit tests only.
kaxil
left a comment
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 @ephraimbuddy for this PR.
How much effort might be required to make it backwards-compatible with deprecation warning, I definitely not saying we should do it --- but would like to hear your opinions @ephraimbuddy @turbaszek @potiuk .
|
CI is failing: |
|
I
I think it's totally not worth it. There are very few issues where people use the CLI to automate stuff for Airflow and for most of them migration to 2.0 will be quite some change anyway (at least running upgrade check). I think we are talking about a handful of users here - far less than people who are writing DAGs and they use CLI either very rarely (db init, db reset etc) so they don't remember the commands by heart, or very frequently use one command ("backfill") but then it will be very easy to adapt to that single command. |
Agree 👍 |
It is like the |
Probably the problem is related to subparsers. The command |
Seen, It also affects backfill, I understand now. |
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.
| msg = "{} command, has been removed, please use `airflow {}`".format(value, COMMAND_MAP[value]) | |
| new_command = COMMAND_MAP[value] | |
| msg = f"`airflow {value}` command, has been removed, please use `airflow {new_command}`" |
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.
Can you give a more descriptive name e.g. check_legacy_commands?
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.
| if COMMAND_MAP.get(value) is not None: | |
| new_command = COMMAND_MAP[value] | |
| new_command = COMMAND_MAP.get(value) | |
| if new_command is not None: | |
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.
If we are using existing command there's no reason to mock I think
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.
Agree!
Closes: #10109
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.