-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Protect against accidental misuse of XCom.get_value()
The XCom.get_value has been added in 2.3.0 and while there are cases it should be used in the providers when task are mapped, in order to keep compatibility with earlier versions of Airlfow, the XCom.get_value() should only be used when ti_key is not None. We check for the construct used in community providers automatically and also add a documentation for users who would like to use dynamic task mapping featuers in their own providers.
- Loading branch information
Showing
15 changed files
with
132 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env python3 | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
import sys | ||
from pathlib import Path | ||
from typing import List | ||
|
||
from rich.console import Console | ||
|
||
if __name__ not in ("__main__", "__mp_main__"): | ||
raise SystemExit( | ||
"This file is intended to be executed as an executable program. You cannot use it as a module." | ||
f"To run this script, run the ./{__file__} command [FILE] ..." | ||
) | ||
|
||
|
||
console = Console(color_system="standard", width=200) | ||
|
||
errors: List[str] = [] | ||
|
||
|
||
def _check_file(_file: Path): | ||
lines = _file.read_text().splitlines() | ||
for index, line in enumerate(lines): | ||
if "XCom.get_value(" in line: | ||
if "if ti_key is not None:" not in lines[index - 1]: | ||
errors.append( | ||
f"[red]In {_file}:{index} there is a forbidden construct " | ||
f"(Airflow 2.3.0 only):[/]\n\n" | ||
f"{lines[index-1]}\n{lines[index]}\n\n" | ||
f"[yellow]When you use XCom.get_value( in providers, it should be in the form:[/]\n\n" | ||
f"if ti_key is not None:\n" | ||
f" value = XCom.get_value(...., ti_key=ti_key)\n\n" | ||
f"See: https://airflow.apache.org/docs/apache-airflow-providers/" | ||
f"howto/create-update-providers.html#using-providers-with-dynamic-task-mapping\n" | ||
) | ||
|
||
|
||
if __name__ == '__main__': | ||
for file in sys.argv[1:]: | ||
_check_file(Path(file)) | ||
if errors: | ||
console.print("[red]Found forbidden usage of XCom.get_value( in providers:[/]\n") | ||
for error in errors: | ||
console.print(f"{error}") | ||
sys.exit(1) |