You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2022/06/22 21:26:44 UTC
[airflow] branch main updated: Upgrade FAB to 4.1.1 (#24399)
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new e2f19505bf Upgrade FAB to 4.1.1 (#24399)
e2f19505bf is described below
commit e2f19505bf3622935480e80bee55bf5b6d80097b
Author: Jarek Potiuk <ja...@polidea.com>
AuthorDate: Wed Jun 22 23:26:28 2022 +0200
Upgrade FAB to 4.1.1 (#24399)
* Upgrade FAB to 4.1.1
The Flask Application Builder have been updated recently to
support a number of newer dependencies. This PR is the
attempt to migrate FAB to newer version.
This includes:
* update setup.py and setup.cfg upper and lower bounds to
account for proper version of dependencies that
FAB < 4.0.0 was blocking from upgrade
* added typed Flask application retrieval with a custom
application fields available for MyPy typing checks.
* fix typing to account for typing hints added in multiple
upgraded libraries optional values and content of request
returned as Mapping
* switch to PyJWT 2.* by using non-deprecated "required" claim as
list rather than separate fields
* add possibiliyt to install providers without constraints
so that we could avoid errors on conflicting constraints when
upgrade-to-newer-dependencies is used
* add pre-commit to check that 2.4+ only get_airflow_app is not
used in providers
* avoid Bad Request in case the request sent to Flask 2.0 is not
JSon content type
* switch imports of internal classes to direct packages
where classes are available rather than from "airflow.models" to
satisfy MyPY
* synchronize changes of FAB Security Manager 4.1.1 with our copy
of the Security Manager.
* add error handling for a few "None" cases detected by MyPY
* corrected test cases that were broken by immutability of
Flask 2 objects and better escaping done by Flask 2
* updated test cases to account for redirection to "path" rather
than full URL by Flask2
Fixes: #22397
* fixup! Upgrade FAB to 4.1.1
---
.github/workflows/ci.yml | 4 +
.pre-commit-config.yaml | 2 +-
Dockerfile.ci | 36 ++-
airflow/api/auth/backend/basic_auth.py | 5 +-
airflow/api_connexion/endpoints/dag_endpoint.py | 9 +-
.../api_connexion/endpoints/dag_run_endpoint.py | 26 +-
.../api_connexion/endpoints/extra_link_endpoint.py | 4 +-
airflow/api_connexion/endpoints/log_endpoint.py | 11 +-
airflow/api_connexion/endpoints/pool_endpoint.py | 14 +-
airflow/api_connexion/endpoints/request_dict.py | 24 ++
.../endpoints/role_and_permission_endpoint.py | 15 +-
airflow/api_connexion/endpoints/task_endpoint.py | 7 +-
.../endpoints/task_instance_endpoint.py | 17 +-
airflow/api_connexion/endpoints/user_endpoint.py | 13 +-
.../api_connexion/endpoints/variable_endpoint.py | 7 +-
airflow/api_connexion/endpoints/xcom_endpoint.py | 5 +-
airflow/api_connexion/schemas/dag_schema.py | 2 +-
.../api_connexion/schemas/task_instance_schema.py | 2 +-
airflow/api_connexion/security.py | 7 +-
airflow/models/abstractoperator.py | 1 -
airflow/operators/trigger_dagrun.py | 5 +-
.../google/common/auth_backend/google_openid.py | 2 +-
airflow/sensors/external_task.py | 6 +-
airflow/utils/airflow_flask_app.py | 37 +++
airflow/utils/jwt_signer.py | 4 +-
airflow/www/api/experimental/endpoints.py | 3 +-
airflow/www/auth.py | 5 +-
airflow/www/extensions/init_wsgi_middlewares.py | 2 +-
airflow/www/fab_security/manager.py | 37 ++-
airflow/www/views.py | 118 ++++----
dev/breeze/README.md | 2 +-
dev/breeze/setup.cfg | 2 +-
.../commands/release_management_commands.py | 9 +
.../src/airflow_breeze/params/shell_params.py | 1 +
.../airflow_breeze/utils/docker_command_utils.py | 1 +
dev/breeze/src/airflow_breeze/utils/recording.py | 4 +-
dev/send_email.py | 3 +-
images/breeze/output-commands-hash.txt | 2 +-
images/breeze/output-verify-provider-packages.svg | 140 ++++-----
newsfragments/24399.significant.rst | 31 ++
scripts/ci/docker-compose/_docker.env | 1 +
scripts/ci/docker-compose/base.yml | 1 +
scripts/ci/docker-compose/devcontainer.env | 1 +
.../pre_commit_check_2_2_compatibility.py | 40 ++-
scripts/docker/entrypoint_ci.sh | 36 ++-
scripts/in_container/_in_container_utils.sh | 29 +-
setup.cfg | 47 +--
setup.py | 12 +-
tests/api_connexion/endpoints/test_dag_endpoint.py | 97 ++++---
.../endpoints/test_dag_source_endpoint.py | 27 +-
.../api_connexion/endpoints/test_xcom_endpoint.py | 6 +-
tests/api_connexion/schemas/test_dag_schema.py | 321 ++++++++++-----------
tests/conftest.py | 24 ++
tests/test_utils/remote_user_api_auth_backend.py | 6 +-
tests/utils/test_serve_logs.py | 13 +-
tests/www/views/test_views.py | 25 +-
tests/www/views/test_views_decorators.py | 6 +-
tests/www/views/test_views_log.py | 2 +-
tests/www/views/test_views_mount.py | 4 +-
59 files changed, 762 insertions(+), 561 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 5450833f23..0cea9d687f 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -805,6 +805,8 @@ ${{ hashFiles('.pre-commit-config.yaml') }}"
run: >
breeze verify-provider-packages --use-airflow-version wheel --use-packages-from-dist
--package-format wheel
+ env:
+ SKIP_CONSTRAINTS: "${{ needs.build-info.outputs.upgradeToNewerDependencies }}"
- name: "Remove airflow package and replace providers with 2.2-compliant versions"
run: |
rm -vf dist/apache_airflow-*.whl \
@@ -882,6 +884,8 @@ ${{ hashFiles('.pre-commit-config.yaml') }}"
run: >
breeze verify-provider-packages --use-airflow-version sdist --use-packages-from-dist
--package-format sdist
+ env:
+ SKIP_CONSTRAINTS: "${{ needs.build-info.outputs.upgradeToNewerDependencies }}"
- name: "Fix ownership"
run: breeze fix-ownership
if: always()
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 0692904ce5..fc72d47c25 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -347,7 +347,7 @@ repos:
language: python
files: ^BREEZE\.rst$|^dev/breeze/.*$
pass_filenames: false
- additional_dependencies: ['rich>=12.4.4', 'rich-click']
+ additional_dependencies: ['rich>=12.4.4', 'rich-click>=1.5']
- id: update-local-yml-file
name: Update mounts in the local yml file
entry: ./scripts/ci/pre_commit/pre_commit_local_yml_mounts.py
diff --git a/Dockerfile.ci b/Dockerfile.ci
index 7bf6257f53..e9f3f4b428 100644
--- a/Dockerfile.ci
+++ b/Dockerfile.ci
@@ -686,9 +686,15 @@ if [[ ${SKIP_ENVIRONMENT_INITIALIZATION=} != "true" ]]; then
echo "${COLOR_BLUE}Uninstalling airflow and providers"
echo
uninstall_airflow_and_providers
- echo "${COLOR_BLUE}Install airflow from wheel package with extras: '${AIRFLOW_EXTRAS}' and constraints reference ${AIRFLOW_CONSTRAINTS_REFERENCE}.${COLOR_RESET}"
- echo
- install_airflow_from_wheel "${AIRFLOW_EXTRAS}" "${AIRFLOW_CONSTRAINTS_REFERENCE}"
+ if [[ ${SKIP_CONSTRAINTS,,=} == "true" ]]; then
+ echo "${COLOR_BLUE}Install airflow from wheel package with extras: '${AIRFLOW_EXTRAS}' with no constraints.${COLOR_RESET}"
+ echo
+ install_airflow_from_wheel "${AIRFLOW_EXTRAS}" "none"
+ else
+ echo "${COLOR_BLUE}Install airflow from wheel package with extras: '${AIRFLOW_EXTRAS}' and constraints reference ${AIRFLOW_CONSTRAINTS_REFERENCE}.${COLOR_RESET}"
+ echo
+ install_airflow_from_wheel "${AIRFLOW_EXTRAS}" "${AIRFLOW_CONSTRAINTS_REFERENCE}"
+ fi
uninstall_providers
elif [[ ${USE_AIRFLOW_VERSION} == "sdist" ]]; then
echo
@@ -696,9 +702,15 @@ if [[ ${SKIP_ENVIRONMENT_INITIALIZATION=} != "true" ]]; then
echo
uninstall_airflow_and_providers
echo
- echo "${COLOR_BLUE}Install airflow from sdist package with extras: '${AIRFLOW_EXTRAS}' and constraints reference ${AIRFLOW_CONSTRAINTS_REFERENCE}.${COLOR_RESET}"
- echo
- install_airflow_from_sdist "${AIRFLOW_EXTRAS}" "${AIRFLOW_CONSTRAINTS_REFERENCE}"
+ if [[ ${SKIP_CONSTRAINTS,,=} == "true" ]]; then
+ echo "${COLOR_BLUE}Install airflow from sdist package with extras: '${AIRFLOW_EXTRAS}' with no constraints.${COLOR_RESET}"
+ echo
+ install_airflow_from_sdist "${AIRFLOW_EXTRAS}" "none"
+ else
+ echo "${COLOR_BLUE}Install airflow from sdist package with extras: '${AIRFLOW_EXTRAS}' and constraints reference ${AIRFLOW_CONSTRAINTS_REFERENCE}.${COLOR_RESET}"
+ echo
+ install_airflow_from_sdist "${AIRFLOW_EXTRAS}" "${AIRFLOW_CONSTRAINTS_REFERENCE}"
+ fi
uninstall_providers
else
echo
@@ -706,9 +718,15 @@ if [[ ${SKIP_ENVIRONMENT_INITIALIZATION=} != "true" ]]; then
echo
uninstall_airflow_and_providers
echo
- echo "${COLOR_BLUE}Install released airflow from PyPI with extras: '${AIRFLOW_EXTRAS}' and constraints reference ${AIRFLOW_CONSTRAINTS_REFERENCE}.${COLOR_RESET}"
- echo
- install_released_airflow_version "${USE_AIRFLOW_VERSION}" "${AIRFLOW_CONSTRAINTS_REFERENCE}"
+ if [[ ${SKIP_CONSTRAINTS,,=} == "true" ]]; then
+ echo "${COLOR_BLUE}Install released airflow from PyPI with extras: '${AIRFLOW_EXTRAS}' with no constraints.${COLOR_RESET}"
+ echo
+ install_released_airflow_version "${USE_AIRFLOW_VERSION}" "none"
+ else
+ echo "${COLOR_BLUE}Install released airflow from PyPI with extras: '${AIRFLOW_EXTRAS}' and constraints reference ${AIRFLOW_CONSTRAINTS_REFERENCE}.${COLOR_RESET}"
+ echo
+ install_released_airflow_version "${USE_AIRFLOW_VERSION}" "${AIRFLOW_CONSTRAINTS_REFERENCE}"
+ fi
fi
if [[ ${USE_PACKAGES_FROM_DIST=} == "true" ]]; then
echo
diff --git a/airflow/api/auth/backend/basic_auth.py b/airflow/api/auth/backend/basic_auth.py
index 397a722a98..12f00b435f 100644
--- a/airflow/api/auth/backend/basic_auth.py
+++ b/airflow/api/auth/backend/basic_auth.py
@@ -18,10 +18,11 @@
from functools import wraps
from typing import Any, Callable, Optional, Tuple, TypeVar, Union, cast
-from flask import Response, current_app, request
+from flask import Response, request
from flask_appbuilder.const import AUTH_LDAP
from flask_login import login_user
+from airflow.utils.airflow_flask_app import get_airflow_app
from airflow.www.fab_security.sqla.models import User
CLIENT_AUTH: Optional[Union[Tuple[str, str], Any]] = None
@@ -40,7 +41,7 @@ def auth_current_user() -> Optional[User]:
if auth is None or not auth.username or not auth.password:
return None
- ab_security_manager = current_app.appbuilder.sm
+ ab_security_manager = get_airflow_app().appbuilder.sm
user = None
if ab_security_manager.auth_type == AUTH_LDAP:
user = ab_security_manager.auth_user_ldap(auth.username, auth.password)
diff --git a/airflow/api_connexion/endpoints/dag_endpoint.py b/airflow/api_connexion/endpoints/dag_endpoint.py
index 0505f864ee..7940a25c8f 100644
--- a/airflow/api_connexion/endpoints/dag_endpoint.py
+++ b/airflow/api_connexion/endpoints/dag_endpoint.py
@@ -19,7 +19,7 @@ from http import HTTPStatus
from typing import Collection, Optional
from connexion import NoContent
-from flask import current_app, g, request
+from flask import g, request
from marshmallow import ValidationError
from sqlalchemy.orm import Session
from sqlalchemy.sql.expression import or_
@@ -38,6 +38,7 @@ from airflow.api_connexion.types import APIResponse, UpdateMask
from airflow.exceptions import AirflowException, DagNotFound
from airflow.models.dag import DagModel, DagTag
from airflow.security import permissions
+from airflow.utils.airflow_flask_app import get_airflow_app
from airflow.utils.session import NEW_SESSION, provide_session
@@ -56,7 +57,7 @@ def get_dag(*, dag_id: str, session: Session = NEW_SESSION) -> APIResponse:
@security.requires_access([(permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG)])
def get_dag_details(*, dag_id: str) -> APIResponse:
"""Get details of DAG."""
- dag: DAG = current_app.dag_bag.get_dag(dag_id)
+ dag: DAG = get_airflow_app().dag_bag.get_dag(dag_id)
if not dag:
raise NotFound("DAG not found", detail=f"The DAG with dag_id: {dag_id} was not found")
return dag_detail_schema.dump(dag)
@@ -83,7 +84,7 @@ def get_dags(
if dag_id_pattern:
dags_query = dags_query.filter(DagModel.dag_id.ilike(f'%{dag_id_pattern}%'))
- readable_dags = current_app.appbuilder.sm.get_accessible_dag_ids(g.user)
+ readable_dags = get_airflow_app().appbuilder.sm.get_accessible_dag_ids(g.user)
dags_query = dags_query.filter(DagModel.dag_id.in_(readable_dags))
if tags:
@@ -143,7 +144,7 @@ def patch_dags(limit, session, offset=0, only_active=True, tags=None, dag_id_pat
if dag_id_pattern == '~':
dag_id_pattern = '%'
dags_query = dags_query.filter(DagModel.dag_id.ilike(f'%{dag_id_pattern}%'))
- editable_dags = current_app.appbuilder.sm.get_editable_dag_ids(g.user)
+ editable_dags = get_airflow_app().appbuilder.sm.get_editable_dag_ids(g.user)
dags_query = dags_query.filter(DagModel.dag_id.in_(editable_dags))
if tags:
diff --git a/airflow/api_connexion/endpoints/dag_run_endpoint.py b/airflow/api_connexion/endpoints/dag_run_endpoint.py
index e510126534..f31b6a24ce 100644
--- a/airflow/api_connexion/endpoints/dag_run_endpoint.py
+++ b/airflow/api_connexion/endpoints/dag_run_endpoint.py
@@ -19,7 +19,7 @@ from typing import List, Optional, Tuple
import pendulum
from connexion import NoContent
-from flask import current_app, g, request
+from flask import g
from marshmallow import ValidationError
from sqlalchemy import or_
from sqlalchemy.orm import Query, Session
@@ -30,6 +30,7 @@ from airflow.api.common.mark_tasks import (
set_dag_run_state_to_success,
)
from airflow.api_connexion import security
+from airflow.api_connexion.endpoints.request_dict import get_json_request_dict
from airflow.api_connexion.exceptions import AlreadyExists, BadRequest, NotFound
from airflow.api_connexion.parameters import apply_sorting, check_limit, format_datetime, format_parameters
from airflow.api_connexion.schemas.dag_run_schema import (
@@ -47,6 +48,7 @@ from airflow.api_connexion.schemas.task_instance_schema import (
from airflow.api_connexion.types import APIResponse
from airflow.models import DagModel, DagRun
from airflow.security import permissions
+from airflow.utils.airflow_flask_app import get_airflow_app
from airflow.utils.session import NEW_SESSION, provide_session
from airflow.utils.state import DagRunState
from airflow.utils.types import DagRunType
@@ -167,7 +169,7 @@ def get_dag_runs(
# This endpoint allows specifying ~ as the dag_id to retrieve DAG Runs for all DAGs.
if dag_id == "~":
- appbuilder = current_app.appbuilder
+ appbuilder = get_airflow_app().appbuilder
query = query.filter(DagRun.dag_id.in_(appbuilder.sm.get_readable_dag_ids(g.user)))
else:
query = query.filter(DagRun.dag_id == dag_id)
@@ -199,13 +201,13 @@ def get_dag_runs(
@provide_session
def get_dag_runs_batch(*, session: Session = NEW_SESSION) -> APIResponse:
"""Get list of DAG Runs"""
- body = request.get_json()
+ body = get_json_request_dict()
try:
data = dagruns_batch_form_schema.load(body)
except ValidationError as err:
raise BadRequest(detail=str(err.messages))
- appbuilder = current_app.appbuilder
+ appbuilder = get_airflow_app().appbuilder
readable_dag_ids = appbuilder.sm.get_readable_dag_ids(g.user)
query = session.query(DagRun)
if data.get("dag_ids"):
@@ -252,7 +254,7 @@ def post_dag_run(*, dag_id: str, session: Session = NEW_SESSION) -> APIResponse:
detail=f"DAG with dag_id: '{dag_id}' has import errors",
)
try:
- post_body = dagrun_schema.load(request.json, session=session)
+ post_body = dagrun_schema.load(get_json_request_dict(), session=session)
except ValidationError as err:
raise BadRequest(detail=str(err))
@@ -268,7 +270,7 @@ def post_dag_run(*, dag_id: str, session: Session = NEW_SESSION) -> APIResponse:
)
if not dagrun_instance:
try:
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
dag_run = dag.create_dagrun(
run_type=DagRunType.MANUAL,
run_id=run_id,
@@ -277,7 +279,7 @@ def post_dag_run(*, dag_id: str, session: Session = NEW_SESSION) -> APIResponse:
state=DagRunState.QUEUED,
conf=post_body.get("conf"),
external_trigger=True,
- dag_hash=current_app.dag_bag.dags_hash.get(dag_id),
+ dag_hash=get_airflow_app().dag_bag.dags_hash.get(dag_id),
)
return dagrun_schema.dump(dag_run)
except ValueError as ve:
@@ -310,12 +312,12 @@ def update_dag_run_state(*, dag_id: str, dag_run_id: str, session: Session = NEW
error_message = f'Dag Run id {dag_run_id} not found in dag {dag_id}'
raise NotFound(error_message)
try:
- post_body = set_dagrun_state_form_schema.load(request.json)
+ post_body = set_dagrun_state_form_schema.load(get_json_request_dict())
except ValidationError as err:
raise BadRequest(detail=str(err))
state = post_body['state']
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
if state == DagRunState.SUCCESS:
set_dag_run_state_to_success(dag=dag, run_id=dag_run.run_id, commit=True)
elif state == DagRunState.QUEUED:
@@ -339,15 +341,15 @@ def clear_dag_run(*, dag_id: str, dag_run_id: str, session: Session = NEW_SESSIO
session.query(DagRun).filter(DagRun.dag_id == dag_id, DagRun.run_id == dag_run_id).one_or_none()
)
if dag_run is None:
- error_message = f'Dag Run id {dag_run_id} not found in dag {dag_id}'
+ error_message = f'Dag Run id {dag_run_id} not found in dag {dag_id}'
raise NotFound(error_message)
try:
- post_body = clear_dagrun_form_schema.load(request.json)
+ post_body = clear_dagrun_form_schema.load(get_json_request_dict())
except ValidationError as err:
raise BadRequest(detail=str(err))
dry_run = post_body.get('dry_run', False)
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
start_date = dag_run.logical_date
end_date = dag_run.logical_date
diff --git a/airflow/api_connexion/endpoints/extra_link_endpoint.py b/airflow/api_connexion/endpoints/extra_link_endpoint.py
index 3e9535603b..94b36928bf 100644
--- a/airflow/api_connexion/endpoints/extra_link_endpoint.py
+++ b/airflow/api_connexion/endpoints/extra_link_endpoint.py
@@ -15,7 +15,6 @@
# specific language governing permissions and limitations
# under the License.
-from flask import current_app
from sqlalchemy.orm.session import Session
from airflow import DAG
@@ -25,6 +24,7 @@ from airflow.api_connexion.types import APIResponse
from airflow.exceptions import TaskNotFound
from airflow.models.dagbag import DagBag
from airflow.security import permissions
+from airflow.utils.airflow_flask_app import get_airflow_app
from airflow.utils.session import NEW_SESSION, provide_session
@@ -46,7 +46,7 @@ def get_extra_links(
"""Get extra links for task instance"""
from airflow.models.taskinstance import TaskInstance
- dagbag: DagBag = current_app.dag_bag
+ dagbag: DagBag = get_airflow_app().dag_bag
dag: DAG = dagbag.get_dag(dag_id)
if not dag:
raise NotFound("DAG not found", detail=f'DAG with ID = "{dag_id}" not found')
diff --git a/airflow/api_connexion/endpoints/log_endpoint.py b/airflow/api_connexion/endpoints/log_endpoint.py
index f1335fe527..171cacb076 100644
--- a/airflow/api_connexion/endpoints/log_endpoint.py
+++ b/airflow/api_connexion/endpoints/log_endpoint.py
@@ -14,10 +14,9 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-
from typing import Any, Optional
-from flask import Response, current_app, request
+from flask import Response, request
from itsdangerous.exc import BadSignature
from itsdangerous.url_safe import URLSafeSerializer
from sqlalchemy.orm.session import Session
@@ -29,6 +28,7 @@ from airflow.api_connexion.types import APIResponse
from airflow.exceptions import TaskNotFound
from airflow.models import TaskInstance
from airflow.security import permissions
+from airflow.utils.airflow_flask_app import get_airflow_app
from airflow.utils.log.log_reader import TaskLogReader
from airflow.utils.session import NEW_SESSION, provide_session
@@ -52,7 +52,7 @@ def get_log(
session: Session = NEW_SESSION,
) -> APIResponse:
"""Get logs for specific task instance"""
- key = current_app.config["SECRET_KEY"]
+ key = get_airflow_app().config["SECRET_KEY"]
if not token:
metadata = {}
else:
@@ -87,7 +87,7 @@ def get_log(
metadata['end_of_log'] = True
raise NotFound(title="TaskInstance not found")
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
if dag:
try:
ti.task = dag.get_task(ti.task_id)
@@ -101,7 +101,8 @@ def get_log(
if return_type == 'application/json' or return_type is None: # default
logs, metadata = task_log_reader.read_log_chunks(ti, task_try_number, metadata)
logs = logs[0] if task_try_number is not None else logs
- token = URLSafeSerializer(key).dumps(metadata)
+ # we must have token here, so we can safely ignore it
+ token = URLSafeSerializer(key).dumps(metadata) # type: ignore[assignment]
return logs_schema.dump(LogResponseObject(continuation_token=token, content=logs))
# text/plain. Stream
logs = task_log_reader.read_log_stream(ti, task_try_number, metadata)
diff --git a/airflow/api_connexion/endpoints/pool_endpoint.py b/airflow/api_connexion/endpoints/pool_endpoint.py
index 1d24fea63d..594afeb49b 100644
--- a/airflow/api_connexion/endpoints/pool_endpoint.py
+++ b/airflow/api_connexion/endpoints/pool_endpoint.py
@@ -18,13 +18,14 @@
from http import HTTPStatus
from typing import Optional
-from flask import Response, request
+from flask import Response
from marshmallow import ValidationError
from sqlalchemy import func
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import Session
from airflow.api_connexion import security
+from airflow.api_connexion.endpoints.request_dict import get_json_request_dict
from airflow.api_connexion.exceptions import AlreadyExists, BadRequest, NotFound
from airflow.api_connexion.parameters import apply_sorting, check_limit, format_parameters
from airflow.api_connexion.schemas.pool_schema import PoolCollection, pool_collection_schema, pool_schema
@@ -85,9 +86,10 @@ def patch_pool(
session: Session = NEW_SESSION,
) -> APIResponse:
"""Update a pool"""
+ request_dict = get_json_request_dict()
# Only slots can be modified in 'default_pool'
try:
- if pool_name == Pool.DEFAULT_POOL_NAME and request.json["name"] != Pool.DEFAULT_POOL_NAME:
+ if pool_name == Pool.DEFAULT_POOL_NAME and request_dict["name"] != Pool.DEFAULT_POOL_NAME:
if update_mask and len(update_mask) == 1 and update_mask[0].strip() == "slots":
pass
else:
@@ -100,7 +102,7 @@ def patch_pool(
raise NotFound(detail=f"Pool with name:'{pool_name}' not found")
try:
- patch_body = pool_schema.load(request.json)
+ patch_body = pool_schema.load(request_dict)
except ValidationError as err:
raise BadRequest(detail=str(err.messages))
@@ -121,7 +123,7 @@ def patch_pool(
else:
required_fields = {"name", "slots"}
- fields_diff = required_fields - set(request.json.keys())
+ fields_diff = required_fields - set(get_json_request_dict().keys())
if fields_diff:
raise BadRequest(detail=f"Missing required property(ies): {sorted(fields_diff)}")
@@ -136,12 +138,12 @@ def patch_pool(
def post_pool(*, session: Session = NEW_SESSION) -> APIResponse:
"""Create a pool"""
required_fields = {"name", "slots"} # Pool would require both fields in the post request
- fields_diff = required_fields - set(request.json.keys())
+ fields_diff = required_fields - set(get_json_request_dict().keys())
if fields_diff:
raise BadRequest(detail=f"Missing required property(ies): {sorted(fields_diff)}")
try:
- post_body = pool_schema.load(request.json, session=session)
+ post_body = pool_schema.load(get_json_request_dict(), session=session)
except ValidationError as err:
raise BadRequest(detail=str(err.messages))
diff --git a/airflow/api_connexion/endpoints/request_dict.py b/airflow/api_connexion/endpoints/request_dict.py
new file mode 100644
index 0000000000..4d7ad21250
--- /dev/null
+++ b/airflow/api_connexion/endpoints/request_dict.py
@@ -0,0 +1,24 @@
+# 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.
+
+from typing import Any, Mapping, cast
+
+
+def get_json_request_dict() -> Mapping[str, Any]:
+ from flask import request
+
+ return cast(Mapping[str, Any], request.get_json())
diff --git a/airflow/api_connexion/endpoints/role_and_permission_endpoint.py b/airflow/api_connexion/endpoints/role_and_permission_endpoint.py
index 88a68341c1..1b25769af7 100644
--- a/airflow/api_connexion/endpoints/role_and_permission_endpoint.py
+++ b/airflow/api_connexion/endpoints/role_and_permission_endpoint.py
@@ -19,7 +19,7 @@ from http import HTTPStatus
from typing import List, Optional, Tuple
from connexion import NoContent
-from flask import current_app, request
+from flask import request
from marshmallow import ValidationError
from sqlalchemy import asc, desc, func
@@ -35,6 +35,7 @@ from airflow.api_connexion.schemas.role_and_permission_schema import (
)
from airflow.api_connexion.types import APIResponse, UpdateMask
from airflow.security import permissions
+from airflow.utils.airflow_flask_app import get_airflow_app
from airflow.www.fab_security.sqla.models import Action, Role
from airflow.www.security import AirflowSecurityManager
@@ -55,7 +56,7 @@ def _check_action_and_resource(sm: AirflowSecurityManager, perms: List[Tuple[str
@security.requires_access([(permissions.ACTION_CAN_READ, permissions.RESOURCE_ROLE)])
def get_role(*, role_name: str) -> APIResponse:
"""Get role"""
- ab_security_manager = current_app.appbuilder.sm
+ ab_security_manager = get_airflow_app().appbuilder.sm
role = ab_security_manager.find_role(name=role_name)
if not role:
raise NotFound(title="Role not found", detail=f"Role with name {role_name!r} was not found")
@@ -66,7 +67,7 @@ def get_role(*, role_name: str) -> APIResponse:
@format_parameters({"limit": check_limit})
def get_roles(*, order_by: str = "name", limit: int, offset: Optional[int] = None) -> APIResponse:
"""Get roles"""
- appbuilder = current_app.appbuilder
+ appbuilder = get_airflow_app().appbuilder
session = appbuilder.get_session
total_entries = session.query(func.count(Role.id)).scalar()
direction = desc if order_by.startswith("-") else asc
@@ -90,7 +91,7 @@ def get_roles(*, order_by: str = "name", limit: int, offset: Optional[int] = Non
@format_parameters({'limit': check_limit})
def get_permissions(*, limit: int, offset: Optional[int] = None) -> APIResponse:
"""Get permissions"""
- session = current_app.appbuilder.get_session
+ session = get_airflow_app().appbuilder.get_session
total_entries = session.query(func.count(Action.id)).scalar()
query = session.query(Action)
actions = query.offset(offset).limit(limit).all()
@@ -100,7 +101,7 @@ def get_permissions(*, limit: int, offset: Optional[int] = None) -> APIResponse:
@security.requires_access([(permissions.ACTION_CAN_DELETE, permissions.RESOURCE_ROLE)])
def delete_role(*, role_name: str) -> APIResponse:
"""Delete a role"""
- ab_security_manager = current_app.appbuilder.sm
+ ab_security_manager = get_airflow_app().appbuilder.sm
role = ab_security_manager.find_role(name=role_name)
if not role:
raise NotFound(title="Role not found", detail=f"Role with name {role_name!r} was not found")
@@ -111,7 +112,7 @@ def delete_role(*, role_name: str) -> APIResponse:
@security.requires_access([(permissions.ACTION_CAN_EDIT, permissions.RESOURCE_ROLE)])
def patch_role(*, role_name: str, update_mask: UpdateMask = None) -> APIResponse:
"""Update a role"""
- appbuilder = current_app.appbuilder
+ appbuilder = get_airflow_app().appbuilder
security_manager = appbuilder.sm
body = request.json
try:
@@ -145,7 +146,7 @@ def patch_role(*, role_name: str, update_mask: UpdateMask = None) -> APIResponse
@security.requires_access([(permissions.ACTION_CAN_CREATE, permissions.RESOURCE_ROLE)])
def post_role() -> APIResponse:
"""Create a new role"""
- appbuilder = current_app.appbuilder
+ appbuilder = get_airflow_app().appbuilder
security_manager = appbuilder.sm
body = request.json
try:
diff --git a/airflow/api_connexion/endpoints/task_endpoint.py b/airflow/api_connexion/endpoints/task_endpoint.py
index 28c39b000c..74b6e7e9ee 100644
--- a/airflow/api_connexion/endpoints/task_endpoint.py
+++ b/airflow/api_connexion/endpoints/task_endpoint.py
@@ -16,8 +16,6 @@
# under the License.
from operator import attrgetter
-from flask import current_app
-
from airflow import DAG
from airflow.api_connexion import security
from airflow.api_connexion.exceptions import BadRequest, NotFound
@@ -25,6 +23,7 @@ from airflow.api_connexion.schemas.task_schema import TaskCollection, task_colle
from airflow.api_connexion.types import APIResponse
from airflow.exceptions import TaskNotFound
from airflow.security import permissions
+from airflow.utils.airflow_flask_app import get_airflow_app
@security.requires_access(
@@ -35,7 +34,7 @@ from airflow.security import permissions
)
def get_task(*, dag_id: str, task_id: str) -> APIResponse:
"""Get simplified representation of a task."""
- dag: DAG = current_app.dag_bag.get_dag(dag_id)
+ dag: DAG = get_airflow_app().dag_bag.get_dag(dag_id)
if not dag:
raise NotFound("DAG not found")
@@ -54,7 +53,7 @@ def get_task(*, dag_id: str, task_id: str) -> APIResponse:
)
def get_tasks(*, dag_id: str, order_by: str = "task_id") -> APIResponse:
"""Get tasks for DAG"""
- dag: DAG = current_app.dag_bag.get_dag(dag_id)
+ dag: DAG = get_airflow_app().dag_bag.get_dag(dag_id)
if not dag:
raise NotFound("DAG not found")
tasks = dag.tasks
diff --git a/airflow/api_connexion/endpoints/task_instance_endpoint.py b/airflow/api_connexion/endpoints/task_instance_endpoint.py
index c2416ab0d9..6cc3e784e6 100644
--- a/airflow/api_connexion/endpoints/task_instance_endpoint.py
+++ b/airflow/api_connexion/endpoints/task_instance_endpoint.py
@@ -16,7 +16,6 @@
# under the License.
from typing import Any, Iterable, List, Optional, Tuple, TypeVar
-from flask import current_app, request
from marshmallow import ValidationError
from sqlalchemy import and_, func, or_
from sqlalchemy.exc import MultipleResultsFound
@@ -25,6 +24,7 @@ from sqlalchemy.orm.query import Query
from sqlalchemy.sql import ClauseElement
from airflow.api_connexion import security
+from airflow.api_connexion.endpoints.request_dict import get_json_request_dict
from airflow.api_connexion.exceptions import BadRequest, NotFound
from airflow.api_connexion.parameters import format_datetime, format_parameters
from airflow.api_connexion.schemas.task_instance_schema import (
@@ -42,6 +42,7 @@ from airflow.models import SlaMiss
from airflow.models.dagrun import DagRun as DR
from airflow.models.taskinstance import TaskInstance as TI, clear_task_instances
from airflow.security import permissions
+from airflow.utils.airflow_flask_app import get_airflow_app
from airflow.utils.session import NEW_SESSION, provide_session
from airflow.utils.state import DagRunState, State
@@ -188,7 +189,7 @@ def get_mapped_task_instances(
# 0 can mean a mapped TI that expanded to an empty list, so it is not an automatic 404
if base_query.with_entities(func.count('*')).scalar() == 0:
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
if not dag:
error_message = f"DAG {dag_id} not found"
raise NotFound(error_message)
@@ -364,7 +365,7 @@ def get_task_instances(
@provide_session
def get_task_instances_batch(session: Session = NEW_SESSION) -> APIResponse:
"""Get list of task instances."""
- body = request.get_json()
+ body = get_json_request_dict()
try:
data = task_instance_batch_form.load(body)
except ValidationError as err:
@@ -423,20 +424,20 @@ def get_task_instances_batch(session: Session = NEW_SESSION) -> APIResponse:
@provide_session
def post_clear_task_instances(*, dag_id: str, session: Session = NEW_SESSION) -> APIResponse:
"""Clear task instances."""
- body = request.get_json()
+ body = get_json_request_dict()
try:
data = clear_task_instance_form.load(body)
except ValidationError as err:
raise BadRequest(detail=str(err.messages))
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
if not dag:
error_message = f"Dag id {dag_id} not found"
raise NotFound(error_message)
reset_dag_runs = data.pop('reset_dag_runs')
dry_run = data.pop('dry_run')
# We always pass dry_run here, otherwise this would try to confirm on the terminal!
- task_instances = dag.clear(dry_run=True, dag_bag=current_app.dag_bag, **data)
+ task_instances = dag.clear(dry_run=True, dag_bag=get_airflow_app().dag_bag, **data)
if not dry_run:
clear_task_instances(
task_instances.all(),
@@ -460,14 +461,14 @@ def post_clear_task_instances(*, dag_id: str, session: Session = NEW_SESSION) ->
@provide_session
def post_set_task_instances_state(*, dag_id: str, session: Session = NEW_SESSION) -> APIResponse:
"""Set a state of task instances."""
- body = request.get_json()
+ body = get_json_request_dict()
try:
data = set_task_instance_state_form.load(body)
except ValidationError as err:
raise BadRequest(detail=str(err.messages))
error_message = f"Dag ID {dag_id} not found"
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
if not dag:
raise NotFound(error_message)
diff --git a/airflow/api_connexion/endpoints/user_endpoint.py b/airflow/api_connexion/endpoints/user_endpoint.py
index 6b4e984a69..3ab476e219 100644
--- a/airflow/api_connexion/endpoints/user_endpoint.py
+++ b/airflow/api_connexion/endpoints/user_endpoint.py
@@ -18,7 +18,7 @@ from http import HTTPStatus
from typing import List, Optional
from connexion import NoContent
-from flask import current_app, request
+from flask import request
from marshmallow import ValidationError
from sqlalchemy import asc, desc, func
from werkzeug.security import generate_password_hash
@@ -34,13 +34,14 @@ from airflow.api_connexion.schemas.user_schema import (
)
from airflow.api_connexion.types import APIResponse, UpdateMask
from airflow.security import permissions
+from airflow.utils.airflow_flask_app import get_airflow_app
from airflow.www.fab_security.sqla.models import Role, User
@security.requires_access([(permissions.ACTION_CAN_READ, permissions.RESOURCE_USER)])
def get_user(*, username: str) -> APIResponse:
"""Get a user"""
- ab_security_manager = current_app.appbuilder.sm
+ ab_security_manager = get_airflow_app().appbuilder.sm
user = ab_security_manager.find_user(username=username)
if not user:
raise NotFound(title="User not found", detail=f"The User with username `{username}` was not found")
@@ -51,7 +52,7 @@ def get_user(*, username: str) -> APIResponse:
@format_parameters({"limit": check_limit})
def get_users(*, limit: int, order_by: str = "id", offset: Optional[str] = None) -> APIResponse:
"""Get users"""
- appbuilder = current_app.appbuilder
+ appbuilder = get_airflow_app().appbuilder
session = appbuilder.get_session
total_entries = session.query(func.count(User.id)).scalar()
direction = desc if order_by.startswith("-") else asc
@@ -87,7 +88,7 @@ def post_user() -> APIResponse:
except ValidationError as e:
raise BadRequest(detail=str(e.messages))
- security_manager = current_app.appbuilder.sm
+ security_manager = get_airflow_app().appbuilder.sm
username = data["username"]
email = data["email"]
@@ -130,7 +131,7 @@ def patch_user(*, username: str, update_mask: UpdateMask = None) -> APIResponse:
except ValidationError as e:
raise BadRequest(detail=str(e.messages))
- security_manager = current_app.appbuilder.sm
+ security_manager = get_airflow_app().appbuilder.sm
user = security_manager.find_user(username=username)
if user is None:
@@ -194,7 +195,7 @@ def patch_user(*, username: str, update_mask: UpdateMask = None) -> APIResponse:
@security.requires_access([(permissions.ACTION_CAN_DELETE, permissions.RESOURCE_USER)])
def delete_user(*, username: str) -> APIResponse:
"""Delete a user"""
- security_manager = current_app.appbuilder.sm
+ security_manager = get_airflow_app().appbuilder.sm
user = security_manager.find_user(username=username)
if user is None:
diff --git a/airflow/api_connexion/endpoints/variable_endpoint.py b/airflow/api_connexion/endpoints/variable_endpoint.py
index 487d2cc486..8f039b6fdb 100644
--- a/airflow/api_connexion/endpoints/variable_endpoint.py
+++ b/airflow/api_connexion/endpoints/variable_endpoint.py
@@ -17,12 +17,13 @@
from http import HTTPStatus
from typing import Optional
-from flask import Response, request
+from flask import Response
from marshmallow import ValidationError
from sqlalchemy import func
from sqlalchemy.orm import Session
from airflow.api_connexion import security
+from airflow.api_connexion.endpoints.request_dict import get_json_request_dict
from airflow.api_connexion.exceptions import BadRequest, NotFound
from airflow.api_connexion.parameters import apply_sorting, check_limit, format_parameters
from airflow.api_connexion.schemas.variable_schema import variable_collection_schema, variable_schema
@@ -79,7 +80,7 @@ def get_variables(
def patch_variable(*, variable_key: str, update_mask: UpdateMask = None) -> Response:
"""Update a variable by key"""
try:
- data = variable_schema.load(request.json)
+ data = variable_schema.load(get_json_request_dict())
except ValidationError as err:
raise BadRequest("Invalid Variable schema", detail=str(err.messages))
@@ -100,7 +101,7 @@ def patch_variable(*, variable_key: str, update_mask: UpdateMask = None) -> Resp
def post_variables() -> Response:
"""Create a variable"""
try:
- data = variable_schema.load(request.json)
+ data = variable_schema.load(get_json_request_dict())
except ValidationError as err:
raise BadRequest("Invalid Variable schema", detail=str(err.messages))
diff --git a/airflow/api_connexion/endpoints/xcom_endpoint.py b/airflow/api_connexion/endpoints/xcom_endpoint.py
index 9cc6b6d79a..62c7262f7e 100644
--- a/airflow/api_connexion/endpoints/xcom_endpoint.py
+++ b/airflow/api_connexion/endpoints/xcom_endpoint.py
@@ -16,7 +16,7 @@
# under the License.
from typing import Optional
-from flask import current_app, g
+from flask import g
from sqlalchemy import and_
from sqlalchemy.orm import Session
@@ -27,6 +27,7 @@ from airflow.api_connexion.schemas.xcom_schema import XComCollection, xcom_colle
from airflow.api_connexion.types import APIResponse
from airflow.models import DagRun as DR, XCom
from airflow.security import permissions
+from airflow.utils.airflow_flask_app import get_airflow_app
from airflow.utils.session import NEW_SESSION, provide_session
@@ -52,7 +53,7 @@ def get_xcom_entries(
"""Get all XCom values"""
query = session.query(XCom)
if dag_id == '~':
- appbuilder = current_app.appbuilder
+ appbuilder = get_airflow_app().appbuilder
readable_dag_ids = appbuilder.sm.get_readable_dag_ids(g.user)
query = query.filter(XCom.dag_id.in_(readable_dag_ids))
query = query.join(DR, and_(XCom.dag_id == DR.dag_id, XCom.run_id == DR.run_id))
diff --git a/airflow/api_connexion/schemas/dag_schema.py b/airflow/api_connexion/schemas/dag_schema.py
index 2f36911329..6e7410dc4f 100644
--- a/airflow/api_connexion/schemas/dag_schema.py
+++ b/airflow/api_connexion/schemas/dag_schema.py
@@ -83,7 +83,7 @@ class DAGSchema(SQLAlchemySchema):
@staticmethod
def get_token(obj: DagModel):
"""Return file token"""
- serializer = URLSafeSerializer(conf.get('webserver', 'secret_key'))
+ serializer = URLSafeSerializer(conf.get_mandatory_value('webserver', 'secret_key'))
return serializer.dumps(obj.fileloc)
diff --git a/airflow/api_connexion/schemas/task_instance_schema.py b/airflow/api_connexion/schemas/task_instance_schema.py
index 37005256f6..74824dbaf8 100644
--- a/airflow/api_connexion/schemas/task_instance_schema.py
+++ b/airflow/api_connexion/schemas/task_instance_schema.py
@@ -60,7 +60,7 @@ class TaskInstanceSchema(SQLAlchemySchema):
pid = auto_field()
executor_config = auto_field()
sla_miss = fields.Nested(SlaMissSchema, dump_default=None)
- rendered_fields = JsonObjectField(default={})
+ rendered_fields = JsonObjectField(dump_default={})
def get_attribute(self, obj, attr, default):
if attr == "sla_miss":
diff --git a/airflow/api_connexion/security.py b/airflow/api_connexion/security.py
index 3562c98eb4..6c84181f91 100644
--- a/airflow/api_connexion/security.py
+++ b/airflow/api_connexion/security.py
@@ -18,16 +18,17 @@
from functools import wraps
from typing import Callable, Optional, Sequence, Tuple, TypeVar, cast
-from flask import Response, current_app
+from flask import Response
from airflow.api_connexion.exceptions import PermissionDenied, Unauthenticated
+from airflow.utils.airflow_flask_app import get_airflow_app
T = TypeVar("T", bound=Callable)
def check_authentication() -> None:
"""Checks that the request has valid authorization information."""
- for auth in current_app.api_auth:
+ for auth in get_airflow_app().api_auth:
response = auth.requires_authentication(Response)()
if response.status_code == 200:
return
@@ -38,7 +39,7 @@ def check_authentication() -> None:
def requires_access(permissions: Optional[Sequence[Tuple[str, str]]] = None) -> Callable[[T], T]:
"""Factory for decorator that checks current user's permissions against required permissions."""
- appbuilder = current_app.appbuilder
+ appbuilder = get_airflow_app().appbuilder
appbuilder.sm.sync_resource_permissions(permissions)
def requires_access_decorator(func: T):
diff --git a/airflow/models/abstractoperator.py b/airflow/models/abstractoperator.py
index cb566ea6f9..0645066b0a 100644
--- a/airflow/models/abstractoperator.py
+++ b/airflow/models/abstractoperator.py
@@ -307,7 +307,6 @@ class AbstractOperator(LoggingMixin, DAGNode):
return link.get_link(self, ti_key=ti.key)
else:
return link.get_link(self, ti.dag_run.logical_date) # type: ignore[misc]
- return None
def render_template_fields(
self,
diff --git a/airflow/operators/trigger_dagrun.py b/airflow/operators/trigger_dagrun.py
index 0689f14c56..4578fd2df8 100644
--- a/airflow/operators/trigger_dagrun.py
+++ b/airflow/operators/trigger_dagrun.py
@@ -23,7 +23,10 @@ from typing import TYPE_CHECKING, Dict, List, Optional, Sequence, Union, cast
from airflow.api.common.trigger_dag import trigger_dag
from airflow.exceptions import AirflowException, DagNotFound, DagRunAlreadyExists
-from airflow.models import BaseOperator, BaseOperatorLink, DagBag, DagModel, DagRun
+from airflow.models.baseoperator import BaseOperator, BaseOperatorLink
+from airflow.models.dag import DagModel
+from airflow.models.dagbag import DagBag
+from airflow.models.dagrun import DagRun
from airflow.models.xcom import XCom
from airflow.utils import timezone
from airflow.utils.context import Context
diff --git a/airflow/providers/google/common/auth_backend/google_openid.py b/airflow/providers/google/common/auth_backend/google_openid.py
index 496ac29616..a267c0e63a 100644
--- a/airflow/providers/google/common/auth_backend/google_openid.py
+++ b/airflow/providers/google/common/auth_backend/google_openid.py
@@ -88,7 +88,7 @@ def _verify_id_token(id_token: str) -> Optional[str]:
def _lookup_user(user_email: str):
- security_manager = current_app.appbuilder.sm
+ security_manager = current_app.appbuilder.sm # type: ignore[attr-defined]
user = security_manager.find_user(email=user_email)
if not user:
diff --git a/airflow/sensors/external_task.py b/airflow/sensors/external_task.py
index 9bb074d47c..327fed6db0 100644
--- a/airflow/sensors/external_task.py
+++ b/airflow/sensors/external_task.py
@@ -25,7 +25,11 @@ import attr
from sqlalchemy import func
from airflow.exceptions import AirflowException
-from airflow.models import BaseOperatorLink, DagBag, DagModel, DagRun, TaskInstance
+from airflow.models.baseoperator import BaseOperatorLink
+from airflow.models.dag import DagModel
+from airflow.models.dagbag import DagBag
+from airflow.models.dagrun import DagRun
+from airflow.models.taskinstance import TaskInstance
from airflow.operators.empty import EmptyOperator
from airflow.sensors.base import BaseSensorOperator
from airflow.utils.helpers import build_airflow_url_with_query
diff --git a/airflow/utils/airflow_flask_app.py b/airflow/utils/airflow_flask_app.py
new file mode 100644
index 0000000000..a14ff99398
--- /dev/null
+++ b/airflow/utils/airflow_flask_app.py
@@ -0,0 +1,37 @@
+# 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.
+
+from typing import Any, List, cast
+
+from flask import Flask
+
+from airflow.models.dagbag import DagBag
+from airflow.www.extensions.init_appbuilder import AirflowAppBuilder
+
+
+class AirflowApp(Flask):
+ """Airflow Flask Application"""
+
+ appbuilder: AirflowAppBuilder
+ dag_bag: DagBag
+ api_auth: List[Any]
+
+
+def get_airflow_app() -> AirflowApp:
+ from flask import current_app
+
+ return cast(AirflowApp, current_app)
diff --git a/airflow/utils/jwt_signer.py b/airflow/utils/jwt_signer.py
index 941a3d0598..e767997ebe 100644
--- a/airflow/utils/jwt_signer.py
+++ b/airflow/utils/jwt_signer.py
@@ -73,9 +73,7 @@ class JWTSigner:
algorithms=[self._algorithm],
options={
"verify_signature": True,
- "require_exp": True,
- "require_iat": True,
- "require_nbf": True,
+ "require": ["exp", "iat", "nbf"],
},
audience=self._audience,
)
diff --git a/airflow/www/api/experimental/endpoints.py b/airflow/www/api/experimental/endpoints.py
index 898988db81..75256f1373 100644
--- a/airflow/www/api/experimental/endpoints.py
+++ b/airflow/www/api/experimental/endpoints.py
@@ -70,7 +70,8 @@ def add_deprecation_headers(response: Response):
return response
-api_experimental.after_request(add_deprecation_headers)
+# This API is deprecated. We do not care too much about typing here
+api_experimental.after_request(add_deprecation_headers) # type: ignore[arg-type]
@api_experimental.route('/dags/<string:dag_id>/dag_runs', methods=['POST'])
diff --git a/airflow/www/auth.py b/airflow/www/auth.py
index e95b4f323f..17ac9c2ce4 100644
--- a/airflow/www/auth.py
+++ b/airflow/www/auth.py
@@ -37,7 +37,10 @@ def has_access(permissions: Optional[Sequence[Tuple[str, str]]] = None) -> Calla
appbuilder = current_app.appbuilder
dag_id = (
- request.args.get("dag_id") or request.form.get("dag_id") or (request.json or {}).get("dag_id")
+ request.args.get("dag_id")
+ or request.form.get("dag_id")
+ or (request.is_json and request.json.get("dag_id"))
+ or None
)
if appbuilder.sm.check_authorization(permissions, dag_id):
return func(*args, **kwargs)
diff --git a/airflow/www/extensions/init_wsgi_middlewares.py b/airflow/www/extensions/init_wsgi_middlewares.py
index 0ed78073e9..00c04006ff 100644
--- a/airflow/www/extensions/init_wsgi_middlewares.py
+++ b/airflow/www/extensions/init_wsgi_middlewares.py
@@ -37,7 +37,7 @@ def init_wsgi_middleware(flask_app: Flask):
base_url = ""
if base_url:
flask_app.wsgi_app = DispatcherMiddleware( # type: ignore
- _root_app, mounts={base_url: flask_app.wsgi_app}
+ _root_app, mounts={base_url: flask_app.wsgi_app} # type: ignore
)
# Apply ProxyFix middleware
diff --git a/airflow/www/fab_security/manager.py b/airflow/www/fab_security/manager.py
index 50e36cfa99..8399f11df3 100644
--- a/airflow/www/fab_security/manager.py
+++ b/airflow/www/fab_security/manager.py
@@ -291,7 +291,7 @@ class BaseSecurityManager:
"""
jwt_manager = JWTManager()
jwt_manager.init_app(app)
- jwt_manager.user_loader_callback_loader(self.load_user_jwt)
+ jwt_manager.user_lookup_loader(self.load_user_jwt)
return jwt_manager
def create_builtin_roles(self):
@@ -654,6 +654,18 @@ class BaseSecurityManager:
"email": data.get("email", ""),
"role_keys": data.get("groups", []),
}
+ # for Keycloak
+ if provider in ["keycloak", "keycloak_before_17"]:
+ me = self.appbuilder.sm.oauth_remotes[provider].get("openid-connect/userinfo")
+ me.raise_for_status()
+ data = me.json()
+ log.debug("User info from Keycloak: %s", data)
+ return {
+ "username": data.get("preferred_username", ""),
+ "first_name": data.get("given_name", ""),
+ "last_name": data.get("family_name", ""),
+ "email": data.get("email", ""),
+ }
else:
return {}
@@ -1028,12 +1040,6 @@ class BaseSecurityManager:
try:
# LDAP certificate settings
- if self.auth_ldap_allow_self_signed:
- ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_ALLOW)
- ldap.set_option(ldap.OPT_X_TLS_NEWCTX, 0)
- elif self.auth_ldap_tls_demand:
- ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_DEMAND)
- ldap.set_option(ldap.OPT_X_TLS_NEWCTX, 0)
if self.auth_ldap_tls_cacertdir:
ldap.set_option(ldap.OPT_X_TLS_CACERTDIR, self.auth_ldap_tls_cacertdir)
if self.auth_ldap_tls_cacertfile:
@@ -1042,6 +1048,12 @@ class BaseSecurityManager:
ldap.set_option(ldap.OPT_X_TLS_CERTFILE, self.auth_ldap_tls_certfile)
if self.auth_ldap_tls_keyfile:
ldap.set_option(ldap.OPT_X_TLS_KEYFILE, self.auth_ldap_tls_keyfile)
+ if self.auth_ldap_allow_self_signed:
+ ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_ALLOW)
+ ldap.set_option(ldap.OPT_X_TLS_NEWCTX, 0)
+ elif self.auth_ldap_tls_demand:
+ ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_DEMAND)
+ ldap.set_option(ldap.OPT_X_TLS_NEWCTX, 0)
# Initialise LDAP connection
con = ldap.initialize(self.auth_ldap_server)
@@ -1355,7 +1367,10 @@ class BaseSecurityManager:
return self._get_user_permission_resources(g.user, "menu_access", resource_names=menu_names)
elif current_user_jwt:
return self._get_user_permission_resources(
- current_user_jwt, "menu_access", resource_names=menu_names
+ # the current_user_jwt is a lazy proxy, so we need to ignore type checking
+ current_user_jwt, # type: ignore[arg-type]
+ "menu_access",
+ resource_names=menu_names,
)
else:
return self._get_user_permission_resources(None, "menu_access", resource_names=menu_names)
@@ -1661,9 +1676,9 @@ class BaseSecurityManager:
"""Load user by ID"""
return self.get_user_by_id(int(user_id))
- def load_user_jwt(self, user_id):
- """Load user JWT"""
- user = self.load_user(user_id)
+ def load_user_jwt(self, _jwt_header, jwt_data):
+ identity = jwt_data["sub"]
+ user = self.load_user(identity)
# Set flask g.user to JWT user, we can't do it on before request
g.user = user
return user
diff --git a/airflow/www/views.py b/airflow/www/views.py
index 5333b31572..bfd5ed462c 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -44,7 +44,6 @@ from flask import (
Response,
abort,
before_render_template,
- current_app,
flash,
g,
jsonify,
@@ -120,6 +119,7 @@ from airflow.ti_deps.dependencies_deps import RUNNING_DEPS, SCHEDULER_QUEUED_DEP
from airflow.timetables.base import DataInterval, TimeRestriction
from airflow.timetables.interval import CronDataIntervalTimetable
from airflow.utils import json as utils_json, timezone, yaml
+from airflow.utils.airflow_flask_app import get_airflow_app
from airflow.utils.dates import infer_time_unit, scale_time_units
from airflow.utils.docs import get_doc_url_for_provider, get_docs_url
from airflow.utils.helpers import alchemy_to_dict
@@ -723,13 +723,13 @@ def add_user_permissions_to_dag(sender, template, context, **extra):
"""
if 'dag' in context:
dag = context['dag']
- can_create_dag_run = current_app.appbuilder.sm.has_access(
+ can_create_dag_run = get_airflow_app().appbuilder.sm.has_access(
permissions.ACTION_CAN_CREATE, permissions.RESOURCE_DAG_RUN
)
- dag.can_edit = current_app.appbuilder.sm.can_edit_dag(dag.dag_id)
+ dag.can_edit = get_airflow_app().appbuilder.sm.can_edit_dag(dag.dag_id)
dag.can_trigger = dag.can_edit and can_create_dag_run
- dag.can_delete = current_app.appbuilder.sm.can_delete_dag(dag.dag_id)
+ dag.can_delete = get_airflow_app().appbuilder.sm.can_delete_dag(dag.dag_id)
context['dag'] = dag
@@ -816,7 +816,7 @@ class Airflow(AirflowBaseView):
end = start + dags_per_page
# Get all the dag id the user could access
- filter_dag_ids = current_app.appbuilder.sm.get_accessible_dag_ids(g.user)
+ filter_dag_ids = get_airflow_app().appbuilder.sm.get_accessible_dag_ids(g.user)
with create_session() as session:
# read orm_dags from the db
@@ -925,7 +925,7 @@ class Airflow(AirflowBaseView):
)
dashboard_alerts = [
- fm for fm in settings.DASHBOARD_UIALERTS if fm.should_show(current_app.appbuilder.sm)
+ fm for fm in settings.DASHBOARD_UIALERTS if fm.should_show(get_airflow_app().appbuilder.sm)
]
def _iter_parsed_moved_data_table_names():
@@ -1006,7 +1006,7 @@ class Airflow(AirflowBaseView):
"""Dag statistics."""
dr = models.DagRun
- allowed_dag_ids = current_app.appbuilder.sm.get_accessible_dag_ids(g.user)
+ allowed_dag_ids = get_airflow_app().appbuilder.sm.get_accessible_dag_ids(g.user)
dag_state_stats = session.query(dr.dag_id, dr.state, sqla.func.count(dr.state)).group_by(
dr.dag_id, dr.state
@@ -1051,7 +1051,7 @@ class Airflow(AirflowBaseView):
@provide_session
def task_stats(self, session=None):
"""Task Statistics"""
- allowed_dag_ids = current_app.appbuilder.sm.get_accessible_dag_ids(g.user)
+ allowed_dag_ids = get_airflow_app().appbuilder.sm.get_accessible_dag_ids(g.user)
if not allowed_dag_ids:
return wwwutils.json_response({})
@@ -1160,7 +1160,7 @@ class Airflow(AirflowBaseView):
@provide_session
def last_dagruns(self, session=None):
"""Last DAG runs"""
- allowed_dag_ids = current_app.appbuilder.sm.get_accessible_dag_ids(g.user)
+ allowed_dag_ids = get_airflow_app().appbuilder.sm.get_accessible_dag_ids(g.user)
# Filter by post parameters
selected_dag_ids = {unquote(dag_id) for dag_id in request.form.getlist('dag_ids') if dag_id}
@@ -1285,7 +1285,7 @@ class Airflow(AirflowBaseView):
@provide_session
def dag_details(self, dag_id, session=None):
"""Get Dag details."""
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
dag_model = DagModel.get_dagmodel(dag_id, session=session)
title = "DAG Details"
@@ -1362,7 +1362,7 @@ class Airflow(AirflowBaseView):
root = request.args.get('root', '')
logging.info("Retrieving rendered templates.")
- dag: DAG = current_app.dag_bag.get_dag(dag_id)
+ dag: DAG = get_airflow_app().dag_bag.get_dag(dag_id)
dag_run = dag.get_dagrun(execution_date=dttm, session=session)
raw_task = dag.get_task(task_id).prepare_for_execution()
@@ -1457,15 +1457,17 @@ class Airflow(AirflowBaseView):
abort(404)
dag_id = request.args.get('dag_id')
task_id = request.args.get('task_id')
+ if task_id is None:
+ logging.warning("Task id not passed in the request")
+ abort(400)
execution_date = request.args.get('execution_date')
dttm = _safe_parse_datetime(execution_date)
-
form = DateTimeForm(data={'execution_date': dttm})
root = request.args.get('root', '')
map_index = request.args.get('map_index', -1, type=int)
logging.info("Retrieving rendered templates.")
- dag: DAG = current_app.dag_bag.get_dag(dag_id)
+ dag: DAG = get_airflow_app().dag_bag.get_dag(dag_id)
task = dag.get_task(task_id)
dag_run = dag.get_dagrun(execution_date=dttm, session=session)
ti = dag_run.get_task_instance(task_id=task.task_id, map_index=map_index, session=session)
@@ -1570,7 +1572,7 @@ class Airflow(AirflowBaseView):
)
try:
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
if dag:
ti.task = dag.get_task(ti.task_id)
@@ -1701,7 +1703,7 @@ class Airflow(AirflowBaseView):
map_index = request.args.get('map_index', -1, type=int)
form = DateTimeForm(data={'execution_date': dttm})
root = request.args.get('root', '')
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
if not dag or task_id not in dag.task_ids:
flash(f"Task [{dag_id}.{task_id}] doesn't seem to exist at the moment", "error")
@@ -1880,7 +1882,7 @@ class Airflow(AirflowBaseView):
dag_run_id = request.form.get('dag_run_id')
map_index = request.args.get('map_index', -1, type=int)
origin = get_safe_url(request.form.get('origin'))
- dag: DAG = current_app.dag_bag.get_dag(dag_id)
+ dag: DAG = get_airflow_app().dag_bag.get_dag(dag_id)
task = dag.get_task(task_id)
ignore_all_deps = request.form.get('ignore_all_deps') == "true"
@@ -1981,7 +1983,7 @@ class Airflow(AirflowBaseView):
request_conf = request.values.get('conf')
request_execution_date = request.values.get('execution_date', default=timezone.utcnow().isoformat())
is_dag_run_conf_overrides_params = conf.getboolean('core', 'dag_run_conf_overrides_params')
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
dag_orm = session.query(models.DagModel).filter(models.DagModel.dag_id == dag_id).first()
if not dag_orm:
flash(f"Cannot find dag {dag_id}")
@@ -2082,7 +2084,7 @@ class Airflow(AirflowBaseView):
state=State.QUEUED,
conf=run_conf,
external_trigger=True,
- dag_hash=current_app.dag_bag.dags_hash.get(dag_id),
+ dag_hash=get_airflow_app().dag_bag.dags_hash.get(dag_id),
run_id=run_id,
)
except (ValueError, ParamValidationError) as ve:
@@ -2164,7 +2166,7 @@ class Airflow(AirflowBaseView):
dag_id = request.form.get('dag_id')
task_id = request.form.get('task_id')
origin = get_safe_url(request.form.get('origin'))
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
if 'map_index' not in request.form:
map_indexes: Optional[List[int]] = None
@@ -2225,7 +2227,7 @@ class Airflow(AirflowBaseView):
dag_run_id = request.form.get('dag_run_id')
confirmed = request.form.get('confirmed') == "true"
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
dr = dag.get_dagrun(run_id=dag_run_id)
start_date = dr.logical_date
end_date = dr.logical_date
@@ -2249,7 +2251,7 @@ class Airflow(AirflowBaseView):
@provide_session
def blocked(self, session=None):
"""Mark Dag Blocked."""
- allowed_dag_ids = current_app.appbuilder.sm.get_accessible_dag_ids(g.user)
+ allowed_dag_ids = get_airflow_app().appbuilder.sm.get_accessible_dag_ids(g.user)
# Filter by post parameters
selected_dag_ids = {unquote(dag_id) for dag_id in request.form.getlist('dag_ids') if dag_id}
@@ -2272,7 +2274,7 @@ class Airflow(AirflowBaseView):
payload = []
for dag_id, active_dag_runs in dags:
max_active_runs = 0
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
if dag:
# TODO: Make max_active_runs a column so we can query for it directly
max_active_runs = dag.max_active_runs
@@ -2289,7 +2291,7 @@ class Airflow(AirflowBaseView):
if not dag_run_id:
return {'status': 'error', 'message': 'Invalid dag_run_id'}
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
if not dag:
return {'status': 'error', 'message': f'Cannot find DAG: {dag_id}'}
@@ -2307,7 +2309,7 @@ class Airflow(AirflowBaseView):
if not dag_run_id:
return {'status': 'error', 'message': 'Invalid dag_run_id'}
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
if not dag:
return {'status': 'error', 'message': f'Cannot find DAG: {dag_id}'}
@@ -2325,7 +2327,7 @@ class Airflow(AirflowBaseView):
if not dag_run_id:
return {'status': 'error', 'message': 'Invalid dag_run_id'}
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
if not dag:
return {'status': 'error', 'message': f'Cannot find DAG: {dag_id}'}
@@ -2399,7 +2401,7 @@ class Airflow(AirflowBaseView):
dag_id = request.args.get("dag_id")
run_id = request.args.get("run_id")
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
dag_run: Optional[DagRun] = (
session.query(DagRun).filter(DagRun.dag_id == dag_id, DagRun.run_id == run_id).one_or_none()
)
@@ -2450,7 +2452,7 @@ class Airflow(AirflowBaseView):
past: bool,
state: TaskInstanceState,
):
- dag: DAG = current_app.dag_bag.get_dag(dag_id)
+ dag: DAG = get_airflow_app().dag_bag.get_dag(dag_id)
if not run_id:
flash(f"Cannot mark tasks as {state}, seem that DAG {dag_id} has never run", "error")
@@ -2498,7 +2500,7 @@ class Airflow(AirflowBaseView):
past = to_boolean(args.get('past'))
origin = origin or url_for('Airflow.index')
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
if not dag:
msg = f'DAG {dag_id} not found'
return redirect_or_json(origin, msg, status='error', status_code=404)
@@ -2687,7 +2689,7 @@ class Airflow(AirflowBaseView):
@provide_session
def grid(self, dag_id, session=None):
"""Get Dag's grid view."""
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
dag_model = DagModel.get_dagmodel(dag_id)
if not dag:
flash(f'DAG "{dag_id}" seems to be missing from DagBag.', "error")
@@ -2797,7 +2799,7 @@ class Airflow(AirflowBaseView):
else:
return func.date(column)
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
dag_model = DagModel.get_dagmodel(dag_id)
if not dag:
flash(f'DAG "{dag_id}" seems to be missing from DagBag.', "error")
@@ -2922,7 +2924,7 @@ class Airflow(AirflowBaseView):
@provide_session
def graph(self, dag_id, session=None):
"""Get DAG as Graph."""
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
dag_model = DagModel.get_dagmodel(dag_id)
if not dag:
flash(f'DAG "{dag_id}" seems to be missing.', "error")
@@ -3035,7 +3037,7 @@ class Airflow(AirflowBaseView):
default_dag_run = conf.getint('webserver', 'default_dag_run_display_number')
dag_model = DagModel.get_dagmodel(dag_id)
- dag: Optional[DAG] = current_app.dag_bag.get_dag(dag_id)
+ dag: Optional[DAG] = get_airflow_app().dag_bag.get_dag(dag_id)
if dag is None:
flash(f'DAG "{dag_id}" seems to be missing.', "error")
return redirect(url_for('Airflow.index'))
@@ -3188,7 +3190,7 @@ class Airflow(AirflowBaseView):
def tries(self, dag_id, session=None):
"""Shows all tries."""
default_dag_run = conf.getint('webserver', 'default_dag_run_display_number')
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
dag_model = DagModel.get_dagmodel(dag_id)
base_date = request.args.get('base_date')
num_runs = request.args.get('num_runs', default=default_dag_run, type=int)
@@ -3279,7 +3281,7 @@ class Airflow(AirflowBaseView):
def landing_times(self, dag_id, session=None):
"""Shows landing times."""
default_dag_run = conf.getint('webserver', 'default_dag_run_display_number')
- dag: DAG = current_app.dag_bag.get_dag(dag_id)
+ dag: DAG = get_airflow_app().dag_bag.get_dag(dag_id)
dag_model = DagModel.get_dagmodel(dag_id)
base_date = request.args.get('base_date')
num_runs = request.args.get('num_runs', default=default_dag_run, type=int)
@@ -3397,7 +3399,7 @@ class Airflow(AirflowBaseView):
@provide_session
def gantt(self, dag_id, session=None):
"""Show GANTT chart."""
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
dag_model = DagModel.get_dagmodel(dag_id)
root = request.args.get('root')
@@ -3524,9 +3526,8 @@ class Airflow(AirflowBaseView):
task_id = request.args.get('task_id')
map_index = request.args.get('map_index', -1, type=int)
execution_date = request.args.get('execution_date')
- link_name = request.args.get('link_name')
dttm = _safe_parse_datetime(execution_date)
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
if not dag or task_id not in dag.task_ids:
response = jsonify(
@@ -3539,6 +3540,11 @@ class Airflow(AirflowBaseView):
return response
task: "AbstractOperator" = dag.get_task(task_id)
+ link_name = request.args.get('link_name')
+ if link_name is None:
+ response = jsonify({'url': None, 'error': 'Link name not passed'})
+ response.status_code = 400
+ return response
ti = (
session.query(TaskInstance)
@@ -3576,7 +3582,7 @@ class Airflow(AirflowBaseView):
def task_instances(self):
"""Shows task instances."""
dag_id = request.args.get('dag_id')
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
dttm = request.args.get('execution_date')
if dttm:
@@ -3604,7 +3610,7 @@ class Airflow(AirflowBaseView):
def grid_data(self):
"""Returns grid data"""
dag_id = request.args.get('dag_id')
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
if not dag:
response = jsonify({'error': f"can't find dag {dag_id}"})
@@ -3658,7 +3664,7 @@ class Airflow(AirflowBaseView):
of the risk associated with exposing Airflow to the public internet, however it does not
address the real security risks associated with such a deployment.
"""
- return send_from_directory(current_app.static_folder, 'robots.txt')
+ return send_from_directory(get_airflow_app().static_folder, 'robots.txt')
@expose('/audit_log')
@auth.has_access(
@@ -3670,7 +3676,7 @@ class Airflow(AirflowBaseView):
@provide_session
def audit_log(self, session=None):
dag_id = request.args.get('dag_id')
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
included_events = conf.get('webserver', 'audit_view_included_events', fallback=None)
excluded_events = conf.get('webserver', 'audit_view_excluded_events', fallback=None)
@@ -3774,9 +3780,9 @@ class DagFilter(BaseFilter):
"""Filter using DagIDs"""
def apply(self, query, func):
- if current_app.appbuilder.sm.has_all_dags_access(g.user):
+ if get_airflow_app().appbuilder.sm.has_all_dags_access(g.user):
return query
- filter_dag_ids = current_app.appbuilder.sm.get_accessible_dag_ids(g.user)
+ filter_dag_ids = get_airflow_app().appbuilder.sm.get_accessible_dag_ids(g.user)
return query.filter(self.model.dag_id.in_(filter_dag_ids))
@@ -3799,7 +3805,7 @@ class AirflowPrivilegeVerifierModelView(AirflowModelView):
@staticmethod
def validate_dag_edit_access(item: Union[DagRun, TaskInstance]):
"""Validates whether the user has 'can_edit' access for this specific DAG."""
- if not current_app.appbuilder.sm.can_edit_dag(item.dag_id):
+ if not get_airflow_app().appbuilder.sm.can_edit_dag(item.dag_id):
raise AirflowException(f"Access denied for dag_id {item.dag_id}")
def pre_add(self, item: Union[DagRun, TaskInstance]):
@@ -3830,7 +3836,7 @@ def action_has_dag_edit_access(action_func: Callable) -> Callable:
items: Optional[Union[List[TaskInstance], List[DagRun], TaskInstance, DagRun]],
*args,
**kwargs,
- ) -> None:
+ ) -> Callable:
if items is None:
dag_ids: Set[str] = set()
elif isinstance(items, list):
@@ -3845,7 +3851,7 @@ def action_has_dag_edit_access(action_func: Callable) -> Callable:
)
for dag_id in dag_ids:
- if not current_app.appbuilder.sm.can_edit_dag(dag_id):
+ if not get_airflow_app().appbuilder.sm.can_edit_dag(dag_id):
flash(f"Access denied for dag_id {dag_id}", "danger")
logging.warning("User %s tried to modify %s without having access.", g.user.username, dag_id)
return redirect(self.get_default_url())
@@ -4448,7 +4454,9 @@ class PoolModelView(AirflowModelView):
def _can_create_variable() -> bool:
- return current_app.appbuilder.sm.has_access(permissions.ACTION_CAN_CREATE, permissions.RESOURCE_VARIABLE)
+ return get_airflow_app().appbuilder.sm.has_access(
+ permissions.ACTION_CAN_CREATE, permissions.RESOURCE_VARIABLE
+ )
class VariableModelView(AirflowModelView):
@@ -4792,7 +4800,10 @@ class DagRunModelView(AirflowPrivilegeVerifierModelView):
for dr in session.query(DagRun).filter(DagRun.id.in_([dagrun.id for dagrun in drs])).all():
count += 1
altered_tis += set_dag_run_state_to_failed(
- dag=current_app.dag_bag.get_dag(dr.dag_id), run_id=dr.run_id, commit=True, session=session
+ dag=get_airflow_app().dag_bag.get_dag(dr.dag_id),
+ run_id=dr.run_id,
+ commit=True,
+ session=session,
)
altered_ti_count = len(altered_tis)
flash(f"{count} dag runs and {altered_ti_count} task instances were set to failed")
@@ -4817,7 +4828,10 @@ class DagRunModelView(AirflowPrivilegeVerifierModelView):
for dr in session.query(DagRun).filter(DagRun.id.in_([dagrun.id for dagrun in drs])).all():
count += 1
altered_tis += set_dag_run_state_to_success(
- dag=current_app.dag_bag.get_dag(dr.dag_id), run_id=dr.run_id, commit=True, session=session
+ dag=get_airflow_app().dag_bag.get_dag(dr.dag_id),
+ run_id=dr.run_id,
+ commit=True,
+ session=session,
)
altered_ti_count = len(altered_tis)
flash(f"{count} dag runs and {altered_ti_count} task instances were set to success")
@@ -4837,7 +4851,7 @@ class DagRunModelView(AirflowPrivilegeVerifierModelView):
dag_to_tis: Dict[DAG, List[TaskInstance]] = {}
for dr in session.query(DagRun).filter(DagRun.id.in_([dagrun.id for dagrun in drs])).all():
count += 1
- dag = current_app.dag_bag.get_dag(dr.dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(dr.dag_id)
tis_to_clear = dag_to_tis.setdefault(dag, [])
tis_to_clear += dr.get_task_instances()
@@ -5130,7 +5144,7 @@ class TaskInstanceModelView(AirflowPrivilegeVerifierModelView):
dag_to_tis = collections.defaultdict(list)
for ti in task_instances:
- dag = current_app.dag_bag.get_dag(ti.dag_id)
+ dag = get_airflow_app().dag_bag.get_dag(ti.dag_id)
dag_to_tis[dag].append(ti)
for dag, task_instances_list in dag_to_tis.items():
@@ -5246,7 +5260,7 @@ class AutocompleteView(AirflowBaseView):
dag_ids_query = dag_ids_query.filter(DagModel.is_paused)
owners_query = owners_query.filter(DagModel.is_paused)
- filter_dag_ids = current_app.appbuilder.sm.get_accessible_dag_ids(g.user)
+ filter_dag_ids = get_airflow_app().appbuilder.sm.get_accessible_dag_ids(g.user)
dag_ids_query = dag_ids_query.filter(DagModel.dag_id.in_(filter_dag_ids))
owners_query = owners_query.filter(DagModel.dag_id.in_(filter_dag_ids))
diff --git a/dev/breeze/README.md b/dev/breeze/README.md
index 7794f25e4e..14a9f089a4 100644
--- a/dev/breeze/README.md
+++ b/dev/breeze/README.md
@@ -52,6 +52,6 @@ PLEASE DO NOT MODIFY THE HASH BELOW! IT IS AUTOMATICALLY UPDATED BY PRE-COMMIT.
---------------------------------------------------------------------------------------------------------
-Package config hash: 40b9b6908905e94c93809cca70c68c632731242798dba9cbe62473e965cb4e5d44eaaa817c5ce9334397f3794a350bc00e3cf319631a25c461a935a389191e7b
+Package config hash: a80a853b2c32c284a68ccd6d468804b892a69f14d2ad1886bdaa892755cf6262660e2b9fc582bcae27ae478910055267a76edea2df658196198a0365150e93e5
---------------------------------------------------------------------------------------------------------
diff --git a/dev/breeze/setup.cfg b/dev/breeze/setup.cfg
index 9c7154ce52..c974560561 100644
--- a/dev/breeze/setup.cfg
+++ b/dev/breeze/setup.cfg
@@ -64,7 +64,7 @@ install_requires =
pyyaml
requests
rich>=12.4.4
- rich_click
+ rich-click>=1.5
[options.packages.find]
where=src
diff --git a/dev/breeze/src/airflow_breeze/commands/release_management_commands.py b/dev/breeze/src/airflow_breeze/commands/release_management_commands.py
index a5333a08ab..caf43d47a4 100644
--- a/dev/breeze/src/airflow_breeze/commands/release_management_commands.py
+++ b/dev/breeze/src/airflow_breeze/commands/release_management_commands.py
@@ -84,6 +84,7 @@ RELEASE_MANAGEMENT_PARAMETERS = {
"--airflow-extras",
"--use-packages-from-dist",
"--package-format",
+ "--skip-constraints",
"--debug",
],
}
@@ -511,6 +512,12 @@ def generate_constraints(
@option_use_airflow_version
@option_airflow_extras
@option_airflow_constraints_reference
+@click.option(
+ "--skip-constraints",
+ is_flag=True,
+ help="Do not use constraints when installing providers.",
+ envvar='SKIP_CONSTRAINTS',
+)
@option_use_packages_from_dist
@option_installation_package_format
@option_verbose
@@ -522,6 +529,7 @@ def verify_provider_packages(
dry_run: bool,
use_airflow_version: Optional[str],
airflow_constraints_reference: str,
+ skip_constraints: bool,
airflow_extras: str,
use_packages_from_dist: bool,
debug: bool,
@@ -538,6 +546,7 @@ def verify_provider_packages(
airflow_extras=airflow_extras,
airflow_constraints_reference=airflow_constraints_reference,
use_packages_from_dist=use_packages_from_dist,
+ skip_constraints=skip_constraints,
package_format=package_format,
)
rebuild_or_pull_ci_image_if_needed(command_params=shell_params, dry_run=dry_run, verbose=verbose)
diff --git a/dev/breeze/src/airflow_breeze/params/shell_params.py b/dev/breeze/src/airflow_breeze/params/shell_params.py
index 8b908aefa7..1b5d6925de 100644
--- a/dev/breeze/src/airflow_breeze/params/shell_params.py
+++ b/dev/breeze/src/airflow_breeze/params/shell_params.py
@@ -81,6 +81,7 @@ class ShellParams:
postgres_version: str = ALLOWED_POSTGRES_VERSIONS[0]
python: str = ALLOWED_PYTHON_MAJOR_MINOR_VERSIONS[0]
skip_environment_initialization: bool = False
+ skip_constraints: bool = False
start_airflow: str = "false"
use_airflow_version: Optional[str] = None
use_packages_from_dist: bool = False
diff --git a/dev/breeze/src/airflow_breeze/utils/docker_command_utils.py b/dev/breeze/src/airflow_breeze/utils/docker_command_utils.py
index 45fd17b858..aca7a4219d 100644
--- a/dev/breeze/src/airflow_breeze/utils/docker_command_utils.py
+++ b/dev/breeze/src/airflow_breeze/utils/docker_command_utils.py
@@ -572,6 +572,7 @@ DERIVE_ENV_VARIABLES_FROM_ATTRIBUTES = {
"POSTGRES_VERSION": "postgres_version",
"SQLITE_URL": "sqlite_url",
"START_AIRFLOW": "start_airflow",
+ "SKIP_CONSTRAINTS": "skip_constraints",
"SKIP_ENVIRONMENT_INITIALIZATION": "skip_environment_initialization",
"USE_AIRFLOW_VERSION": "use_airflow_version",
"USE_PACKAGES_FROM_DIST": "use_packages_from_dist",
diff --git a/dev/breeze/src/airflow_breeze/utils/recording.py b/dev/breeze/src/airflow_breeze/utils/recording.py
index 0ec34edcca..2fe9f5b555 100644
--- a/dev/breeze/src/airflow_breeze/utils/recording.py
+++ b/dev/breeze/src/airflow_breeze/utils/recording.py
@@ -53,10 +53,10 @@ def enable_recording_of_help_output(path: str, title: Optional[str], width: Opti
atexit.register(save_ouput_as_svg)
click.rich_click.MAX_WIDTH = width_int
- click.formatting.FORCED_WIDTH = width_int - 2
+ click.formatting.FORCED_WIDTH = width_int - 2 # type: ignore[attr-defined]
click.rich_click.COLOR_SYSTEM = "standard"
# monkeypatch rich_click console to record help (rich_click does not allow passing extra args to console)
- click.rich_click.Console = RecordingConsole
+ click.rich_click.Console = RecordingConsole # type: ignore[misc]
if output_file_for_recording and not in_autocomplete():
diff --git a/dev/send_email.py b/dev/send_email.py
index 91a35b97cc..2d796eb800 100755
--- a/dev/send_email.py
+++ b/dev/send_email.py
@@ -83,8 +83,7 @@ def show_message(entity: str, message: str):
"""
Show message on the Command Line
"""
- width, _ = click.get_terminal_size()
-
+ width, _ = click.get_terminal_size() # type: ignore[attr-defined]
click.secho("-" * width, fg="blue")
click.secho(f"{entity} Message:", fg="bright_red", bold=True)
click.secho("-" * width, fg="blue")
diff --git a/images/breeze/output-commands-hash.txt b/images/breeze/output-commands-hash.txt
index bf36da39c3..9a22f6dd61 100644
--- a/images/breeze/output-commands-hash.txt
+++ b/images/breeze/output-commands-hash.txt
@@ -2,4 +2,4 @@
# This file is automatically generated by pre-commit. If you have a conflict with this file
# Please do not solve it but run `breeze regenerate-command-images`.
# This command should fix the conflict and regenerate help images that you have conflict with.
-4051e9cd6b50474e5d2c0fb0ec515f33
+e5f34a68b51a9a83e96830bdf837e33f
diff --git a/images/breeze/output-verify-provider-packages.svg b/images/breeze/output-verify-provider-packages.svg
index 12853b46a2..fbfd468ffa 100644
--- a/images/breeze/output-verify-provider-packages.svg
+++ b/images/breeze/output-verify-provider-packages.svg
@@ -1,4 +1,4 @@
-<svg class="rich-terminal" viewBox="0 0 1482 708.8" xmlns="http://www.w3.org/2000/svg">
+<svg class="rich-terminal" viewBox="0 0 1482 733.1999999999999" xmlns="http://www.w3.org/2000/svg">
<!-- Generated with Rich https://www.textualize.io -->
<style>
@@ -19,149 +19,153 @@
font-weight: 700;
}
- .terminal-1578520108-matrix {
+ .terminal-2134602296-matrix {
font-family: Fira Code, monospace;
font-size: 20px;
line-height: 24.4px;
font-variant-east-asian: full-width;
}
- .terminal-1578520108-title {
+ .terminal-2134602296-title {
font-size: 18px;
font-weight: bold;
font-family: arial;
}
- .terminal-1578520108-r1 { fill: #c5c8c6;font-weight: bold }
-.terminal-1578520108-r2 { fill: #c5c8c6 }
-.terminal-1578520108-r3 { fill: #d0b344;font-weight: bold }
-.terminal-1578520108-r4 { fill: #868887 }
-.terminal-1578520108-r5 { fill: #68a0b3;font-weight: bold }
-.terminal-1578520108-r6 { fill: #8d7b39 }
-.terminal-1578520108-r7 { fill: #98a84b;font-weight: bold }
+ .terminal-2134602296-r1 { fill: #c5c8c6;font-weight: bold }
+.terminal-2134602296-r2 { fill: #c5c8c6 }
+.terminal-2134602296-r3 { fill: #d0b344;font-weight: bold }
+.terminal-2134602296-r4 { fill: #868887 }
+.terminal-2134602296-r5 { fill: #68a0b3;font-weight: bold }
+.terminal-2134602296-r6 { fill: #8d7b39 }
+.terminal-2134602296-r7 { fill: #98a84b;font-weight: bold }
</style>
<defs>
- <clipPath id="terminal-1578520108-clip-terminal">
- <rect x="0" y="0" width="1463.0" height="657.8" />
+ <clipPath id="terminal-2134602296-clip-terminal">
+ <rect x="0" y="0" width="1463.0" height="682.1999999999999" />
</clipPath>
- <clipPath id="terminal-1578520108-line-0">
+ <clipPath id="terminal-2134602296-line-0">
<rect x="0" y="1.5" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-1">
+<clipPath id="terminal-2134602296-line-1">
<rect x="0" y="25.9" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-2">
+<clipPath id="terminal-2134602296-line-2">
<rect x="0" y="50.3" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-3">
+<clipPath id="terminal-2134602296-line-3">
<rect x="0" y="74.7" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-4">
+<clipPath id="terminal-2134602296-line-4">
<rect x="0" y="99.1" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-5">
+<clipPath id="terminal-2134602296-line-5">
<rect x="0" y="123.5" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-6">
+<clipPath id="terminal-2134602296-line-6">
<rect x="0" y="147.9" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-7">
+<clipPath id="terminal-2134602296-line-7">
<rect x="0" y="172.3" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-8">
+<clipPath id="terminal-2134602296-line-8">
<rect x="0" y="196.7" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-9">
+<clipPath id="terminal-2134602296-line-9">
<rect x="0" y="221.1" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-10">
+<clipPath id="terminal-2134602296-line-10">
<rect x="0" y="245.5" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-11">
+<clipPath id="terminal-2134602296-line-11">
<rect x="0" y="269.9" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-12">
+<clipPath id="terminal-2134602296-line-12">
<rect x="0" y="294.3" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-13">
+<clipPath id="terminal-2134602296-line-13">
<rect x="0" y="318.7" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-14">
+<clipPath id="terminal-2134602296-line-14">
<rect x="0" y="343.1" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-15">
+<clipPath id="terminal-2134602296-line-15">
<rect x="0" y="367.5" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-16">
+<clipPath id="terminal-2134602296-line-16">
<rect x="0" y="391.9" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-17">
+<clipPath id="terminal-2134602296-line-17">
<rect x="0" y="416.3" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-18">
+<clipPath id="terminal-2134602296-line-18">
<rect x="0" y="440.7" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-19">
+<clipPath id="terminal-2134602296-line-19">
<rect x="0" y="465.1" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-20">
+<clipPath id="terminal-2134602296-line-20">
<rect x="0" y="489.5" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-21">
+<clipPath id="terminal-2134602296-line-21">
<rect x="0" y="513.9" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-22">
+<clipPath id="terminal-2134602296-line-22">
<rect x="0" y="538.3" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-23">
+<clipPath id="terminal-2134602296-line-23">
<rect x="0" y="562.7" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-24">
+<clipPath id="terminal-2134602296-line-24">
<rect x="0" y="587.1" width="1464" height="24.65"/>
</clipPath>
-<clipPath id="terminal-1578520108-line-25">
+<clipPath id="terminal-2134602296-line-25">
<rect x="0" y="611.5" width="1464" height="24.65"/>
</clipPath>
+<clipPath id="terminal-2134602296-line-26">
+ <rect x="0" y="635.9" width="1464" height="24.65"/>
+ </clipPath>
</defs>
- <rect fill="#292929" stroke="rgba(255,255,255,0.35)" stroke-width="1" x="1" y="1" width="1480" height="706.8" rx="8"/><text class="terminal-1578520108-title" fill="#c5c8c6" text-anchor="middle" x="740" y="27">Command: verify-provider-packages</text>
+ <rect fill="#292929" stroke="rgba(255,255,255,0.35)" stroke-width="1" x="1" y="1" width="1480" height="731.2" rx="8"/><text class="terminal-2134602296-title" fill="#c5c8c6" text-anchor="middle" x="740" y="27">Command: verify-provider-packages</text>
<g transform="translate(26,22)">
<circle cx="0" cy="0" r="7" fill="#ff5f57"/>
<circle cx="22" cy="0" r="7" fill="#febc2e"/>
<circle cx="44" cy="0" r="7" fill="#28c840"/>
</g>
- <g transform="translate(9, 41)" clip-path="url(#terminal-1578520108-clip-terminal)">
+ <g transform="translate(9, 41)" clip-path="url(#terminal-2134602296-clip-terminal)">
- <g class="terminal-1578520108-matrix">
- <text class="terminal-1578520108-r2" x="1464" y="20" textLength="12.2" clip-path="url(#terminal-1578520108-line-0)">
-</text><text class="terminal-1578520108-r3" x="12.2" y="44.4" textLength="85.4" clip-path="url(#terminal-1578520108-line-1)">Usage: </text><text class="terminal-1578520108-r1" x="97.6" y="44.4" textLength="500.2" clip-path="url(#terminal-1578520108-line-1)">breeze verify-provider-packages [OPTIONS]</text><text class="terminal-1578520108-r2" x="1464" y="44.4" textLength="12.2" clip-path="url(#terminal-1578520108-line-1)">
-</text><text class="terminal-1578520108-r2" x="1464" y="68.8" textLength="12.2" clip-path="url(#terminal-1578520108-line-2)">
-</text><text class="terminal-1578520108-r2" x="12.2" y="93.2" textLength="854" clip-path="url(#terminal-1578520108-line-3)">Verifies if all provider code is following expectations for providers.</text><text class="terminal-1578520108-r2" x="1464" y="93.2" textLength="12.2" clip-path="url(#terminal-1578520108-line-3)">
-</text><text class="terminal-1578520108-r2" x="1464" y="117.6" textLength="12.2" clip-path="url(#terminal-1578520108-line-4)">
-</text><text class="terminal-1578520108-r4" x="0" y="142" textLength="24.4" clip-path="url(#terminal-1578520108-line-5)">â•─</text><text class="terminal-1578520108-r4" x="24.4" y="142" textLength="1415.2" clip-path="url(#terminal-1578520108-line-5)"> Provider verification flags â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€</text><text class="terminal-1578520108-r4" x="1439.6" y="142" textLength="24.4" clip-path="url(#terminal-1 [...]
-</text><text class="terminal-1578520108-r4" x="0" y="166.4" textLength="12.2" clip-path="url(#terminal-1578520108-line-6)">│</text><text class="terminal-1578520108-r5" x="24.4" y="166.4" textLength="12.2" clip-path="url(#terminal-1578520108-line-6)">-</text><text class="terminal-1578520108-r5" x="36.6" y="166.4" textLength="48.8" clip-path="url(#terminal-1578520108-line-6)">-use</text><text class="terminal-1578520108-r5" x="85.4" y="166.4" textLength="195.2" clip-path="url(#terminal-1578 [...]
-</text><text class="terminal-1578520108-r4" x="0" y="190.8" textLength="12.2" clip-path="url(#terminal-1578520108-line-7)">│</text><text class="terminal-1578520108-r2" x="451.4" y="190.8" textLength="988.2" clip-path="url(#terminal-1578520108-line-7)">`wheel`, or `sdist` if Airflow should be removed, installed from wheel packages  </text><text class="terminal-1578520108-r4" x="1451.8" y="190.8" textLength="12.2" clip-path=" [...]
-</text><text class="terminal-1578520108-r4" x="0" y="215.2" textLength="12.2" clip-path="url(#terminal-1578520108-line-8)">│</text><text class="terminal-1578520108-r2" x="451.4" y="215.2" textLength="793" clip-path="url(#terminal-1578520108-line-8)">or sdist packages available in dist folder respectively. Implies </text><text class="terminal-1578520108-r5" x="1244.4" y="215.2" textLength="12.2" clip-path="url(#terminal-1578520108-line-8)">-</t [...]
-</text><text class="terminal-1578520108-r4" x="0" y="239.6" textLength="12.2" clip-path="url(#terminal-1578520108-line-9)">│</text><text class="terminal-1578520108-r2" x="451.4" y="239.6" textLength="988.2" clip-path="url(#terminal-1578520108-line-9)">`remove`.                                       [...]
-</text><text class="terminal-1578520108-r4" x="0" y="264" textLength="12.2" clip-path="url(#terminal-1578520108-line-10)">│</text><text class="terminal-1578520108-r6" x="451.4" y="264" textLength="988.2" clip-path="url(#terminal-1578520108-line-10)">(none | wheel | sdist | <airflow_version>)                           &# [...]
-</text><text class="terminal-1578520108-r4" x="0" y="288.4" textLength="12.2" clip-path="url(#terminal-1578520108-line-11)">│</text><text class="terminal-1578520108-r5" x="24.4" y="288.4" textLength="12.2" clip-path="url(#terminal-1578520108-line-11)">-</text><text class="terminal-1578520108-r5" x="36.6" y="288.4" textLength="97.6" clip-path="url(#terminal-1578520108-line-11)">-airflow</text><text class="terminal-1578520108-r5" x="134.2" y="288.4" textLength="268.4" clip-path="url(#termi [...]
-</text><text class="terminal-1578520108-r4" x="0" y="312.8" textLength="12.2" clip-path="url(#terminal-1578520108-line-12)">│</text><text class="terminal-1578520108-r2" x="451.4" y="312.8" textLength="988.2" clip-path="url(#terminal-1578520108-line-12)">specify constraints for the installed version and to find newer dependencies     </text><text class="terminal-1578520108-r4" x="1451.8" y="312.8" textLength="12.2" [...]
-</text><text class="terminal-1578520108-r4" x="0" y="337.2" textLength="12.2" clip-path="url(#terminal-1578520108-line-13)">│</text><text class="terminal-1578520108-r6" x="451.4" y="337.2" textLength="988.2" clip-path="url(#terminal-1578520108-line-13)">(TEXT)                                       [...]
-</text><text class="terminal-1578520108-r4" x="0" y="361.6" textLength="12.2" clip-path="url(#terminal-1578520108-line-14)">│</text><text class="terminal-1578520108-r5" x="24.4" y="361.6" textLength="12.2" clip-path="url(#terminal-1578520108-line-14)">-</text><text class="terminal-1578520108-r5" x="36.6" y="361.6" textLength="97.6" clip-path="url(#terminal-1578520108-line-14)">-airflow</text><text class="terminal-1578520108-r5" x="134.2" y="361.6" textLength="85.4" clip-path="url(#termin [...]
-</text><text class="terminal-1578520108-r4" x="0" y="386" textLength="12.2" clip-path="url(#terminal-1578520108-line-15)">│</text><text class="terminal-1578520108-r5" x="24.4" y="386" textLength="12.2" clip-path="url(#terminal-1578520108-line-15)">-</text><text class="terminal-1578520108-r5" x="36.6" y="386" textLength="48.8" clip-path="url(#terminal-1578520108-line-15)">-use</text><text class="terminal-1578520108-r5" x="85.4" y="386" textLength="231.8" clip-path="url(#terminal-157852010 [...]
-</text><text class="terminal-1578520108-r4" x="0" y="410.4" textLength="12.2" clip-path="url(#terminal-1578520108-line-16)">│</text><text class="terminal-1578520108-r2" x="451.4" y="410.4" textLength="988.2" clip-path="url(#terminal-1578520108-line-16)">when entering breeze.                                   [...]
-</text><text class="terminal-1578520108-r4" x="0" y="434.8" textLength="12.2" clip-path="url(#terminal-1578520108-line-17)">│</text><text class="terminal-1578520108-r5" x="24.4" y="434.8" textLength="12.2" clip-path="url(#terminal-1578520108-line-17)">-</text><text class="terminal-1578520108-r5" x="36.6" y="434.8" textLength="97.6" clip-path="url(#terminal-1578520108-line-17)">-package</text><text class="terminal-1578520108-r5" x="134.2" y="434.8" textLength="85.4" clip-path="url(#termin [...]
-</text><text class="terminal-1578520108-r4" x="0" y="459.2" textLength="12.2" clip-path="url(#terminal-1578520108-line-18)">│</text><text class="terminal-1578520108-r4" x="451.4" y="459.2" textLength="658.8" clip-path="url(#terminal-1578520108-line-18)">[default: wheel]                                    & [...]
-</text><text class="terminal-1578520108-r4" x="0" y="483.6" textLength="12.2" clip-path="url(#terminal-1578520108-line-19)">│</text><text class="terminal-1578520108-r5" x="24.4" y="483.6" textLength="12.2" clip-path="url(#terminal-1578520108-line-19)">-</text><text class="terminal-1578520108-r5" x="36.6" y="483.6" textLength="73.2" clip-path="url(#terminal-1578520108-line-19)">-debug</text><text class="terminal-1578520108-r2" x="451.4" y="483.6" textLength="878.4" clip-path="url(#termina [...]
-</text><text class="terminal-1578520108-r4" x="0" y="508" textLength="1464" clip-path="url(#terminal-1578520108-line-20)">╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</text><text class="terminal-1578520108-r2" x="1464" y="508" textLength="12.2" clip-path="url(#terminal-1578520108-line-20)">
-</text><text class="terminal-1578520108-r4" x="0" y="532.4" textLength="24.4" clip-path="url(#terminal-1578520108-line-21)">â•─</text><text class="terminal-1578520108-r4" x="24.4" y="532.4" textLength="1415.2" clip-path="url(#terminal-1578520108-line-21)"> Options â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€</text><text class="terminal-1578520108-r4" x="1439.6" y="532.4" textLength="24.4" clip-path="url(#terminal-157 [...]
-</text><text class="terminal-1578520108-r4" x="0" y="556.8" textLength="12.2" clip-path="url(#terminal-1578520108-line-22)">│</text><text class="terminal-1578520108-r5" x="24.4" y="556.8" textLength="12.2" clip-path="url(#terminal-1578520108-line-22)">-</text><text class="terminal-1578520108-r5" x="36.6" y="556.8" textLength="97.6" clip-path="url(#terminal-1578520108-line-22)">-verbose</text><text class="terminal-1578520108-r7" x="280.6" y="556.8" textLength="24.4" clip-path="url(#termin [...]
-</text><text class="terminal-1578520108-r4" x="0" y="581.2" textLength="12.2" clip-path="url(#terminal-1578520108-line-23)">│</text><text class="terminal-1578520108-r5" x="24.4" y="581.2" textLength="12.2" clip-path="url(#terminal-1578520108-line-23)">-</text><text class="terminal-1578520108-r5" x="36.6" y="581.2" textLength="48.8" clip-path="url(#terminal-1578520108-line-23)">-dry</text><text class="terminal-1578520108-r5" x="85.4" y="581.2" textLength="48.8" clip-path="url(#terminal-15 [...]
-</text><text class="terminal-1578520108-r4" x="0" y="605.6" textLength="12.2" clip-path="url(#terminal-1578520108-line-24)">│</text><text class="terminal-1578520108-r5" x="24.4" y="605.6" textLength="12.2" clip-path="url(#terminal-1578520108-line-24)">-</text><text class="terminal-1578520108-r5" x="36.6" y="605.6" textLength="85.4" clip-path="url(#terminal-1578520108-line-24)">-github</text><text class="terminal-1578520108-r5" x="122" y="605.6" textLength="134.2" clip-path="url(#terminal [...]
-</text><text class="terminal-1578520108-r4" x="0" y="630" textLength="12.2" clip-path="url(#terminal-1578520108-line-25)">│</text><text class="terminal-1578520108-r5" x="24.4" y="630" textLength="12.2" clip-path="url(#terminal-1578520108-line-25)">-</text><text class="terminal-1578520108-r5" x="36.6" y="630" textLength="61" clip-path="url(#terminal-1578520108-line-25)">-help</text><text class="terminal-1578520108-r7" x="280.6" y="630" textLength="24.4" clip-path="url(#terminal-1578520108 [...]
-</text><text class="terminal-1578520108-r4" x="0" y="654.4" textLength="1464" clip-path="url(#terminal-1578520108-line-26)">╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</text><text class="terminal-1578520108-r2" x="1464" y="654.4" textLength="12.2" clip-path="url(#terminal-1578520108-line-26)">
+ <g class="terminal-2134602296-matrix">
+ <text class="terminal-2134602296-r2" x="1464" y="20" textLength="12.2" clip-path="url(#terminal-2134602296-line-0)">
+</text><text class="terminal-2134602296-r3" x="12.2" y="44.4" textLength="85.4" clip-path="url(#terminal-2134602296-line-1)">Usage: </text><text class="terminal-2134602296-r1" x="97.6" y="44.4" textLength="500.2" clip-path="url(#terminal-2134602296-line-1)">breeze verify-provider-packages [OPTIONS]</text><text class="terminal-2134602296-r2" x="1464" y="44.4" textLength="12.2" clip-path="url(#terminal-2134602296-line-1)">
+</text><text class="terminal-2134602296-r2" x="1464" y="68.8" textLength="12.2" clip-path="url(#terminal-2134602296-line-2)">
+</text><text class="terminal-2134602296-r2" x="12.2" y="93.2" textLength="854" clip-path="url(#terminal-2134602296-line-3)">Verifies if all provider code is following expectations for providers.</text><text class="terminal-2134602296-r2" x="1464" y="93.2" textLength="12.2" clip-path="url(#terminal-2134602296-line-3)">
+</text><text class="terminal-2134602296-r2" x="1464" y="117.6" textLength="12.2" clip-path="url(#terminal-2134602296-line-4)">
+</text><text class="terminal-2134602296-r4" x="0" y="142" textLength="24.4" clip-path="url(#terminal-2134602296-line-5)">â•─</text><text class="terminal-2134602296-r4" x="24.4" y="142" textLength="1415.2" clip-path="url(#terminal-2134602296-line-5)"> Provider verification flags â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€</text><text class="terminal-2134602296-r4" x="1439.6" y="142" textLength="24.4" clip-path="url(#terminal-2 [...]
+</text><text class="terminal-2134602296-r4" x="0" y="166.4" textLength="12.2" clip-path="url(#terminal-2134602296-line-6)">│</text><text class="terminal-2134602296-r5" x="24.4" y="166.4" textLength="12.2" clip-path="url(#terminal-2134602296-line-6)">-</text><text class="terminal-2134602296-r5" x="36.6" y="166.4" textLength="48.8" clip-path="url(#terminal-2134602296-line-6)">-use</text><text class="terminal-2134602296-r5" x="85.4" y="166.4" textLength="195.2" clip-path="url(#terminal-2134 [...]
+</text><text class="terminal-2134602296-r4" x="0" y="190.8" textLength="12.2" clip-path="url(#terminal-2134602296-line-7)">│</text><text class="terminal-2134602296-r2" x="451.4" y="190.8" textLength="988.2" clip-path="url(#terminal-2134602296-line-7)">`wheel`, or `sdist` if Airflow should be removed, installed from wheel packages  </text><text class="terminal-2134602296-r4" x="1451.8" y="190.8" textLength="12.2" clip-path=" [...]
+</text><text class="terminal-2134602296-r4" x="0" y="215.2" textLength="12.2" clip-path="url(#terminal-2134602296-line-8)">│</text><text class="terminal-2134602296-r2" x="451.4" y="215.2" textLength="793" clip-path="url(#terminal-2134602296-line-8)">or sdist packages available in dist folder respectively. Implies </text><text class="terminal-2134602296-r5" x="1244.4" y="215.2" textLength="12.2" clip-path="url(#terminal-2134602296-line-8)">-</t [...]
+</text><text class="terminal-2134602296-r4" x="0" y="239.6" textLength="12.2" clip-path="url(#terminal-2134602296-line-9)">│</text><text class="terminal-2134602296-r2" x="451.4" y="239.6" textLength="988.2" clip-path="url(#terminal-2134602296-line-9)">`remove`.                                       [...]
+</text><text class="terminal-2134602296-r4" x="0" y="264" textLength="12.2" clip-path="url(#terminal-2134602296-line-10)">│</text><text class="terminal-2134602296-r6" x="451.4" y="264" textLength="988.2" clip-path="url(#terminal-2134602296-line-10)">(none | wheel | sdist | <airflow_version>)                           &# [...]
+</text><text class="terminal-2134602296-r4" x="0" y="288.4" textLength="12.2" clip-path="url(#terminal-2134602296-line-11)">│</text><text class="terminal-2134602296-r5" x="24.4" y="288.4" textLength="12.2" clip-path="url(#terminal-2134602296-line-11)">-</text><text class="terminal-2134602296-r5" x="36.6" y="288.4" textLength="97.6" clip-path="url(#terminal-2134602296-line-11)">-airflow</text><text class="terminal-2134602296-r5" x="134.2" y="288.4" textLength="268.4" clip-path="url(#termi [...]
+</text><text class="terminal-2134602296-r4" x="0" y="312.8" textLength="12.2" clip-path="url(#terminal-2134602296-line-12)">│</text><text class="terminal-2134602296-r2" x="451.4" y="312.8" textLength="988.2" clip-path="url(#terminal-2134602296-line-12)">specify constraints for the installed version and to find newer dependencies     </text><text class="terminal-2134602296-r4" x="1451.8" y="312.8" textLength="12.2" [...]
+</text><text class="terminal-2134602296-r4" x="0" y="337.2" textLength="12.2" clip-path="url(#terminal-2134602296-line-13)">│</text><text class="terminal-2134602296-r6" x="451.4" y="337.2" textLength="988.2" clip-path="url(#terminal-2134602296-line-13)">(TEXT)                                       [...]
+</text><text class="terminal-2134602296-r4" x="0" y="361.6" textLength="12.2" clip-path="url(#terminal-2134602296-line-14)">│</text><text class="terminal-2134602296-r5" x="24.4" y="361.6" textLength="12.2" clip-path="url(#terminal-2134602296-line-14)">-</text><text class="terminal-2134602296-r5" x="36.6" y="361.6" textLength="97.6" clip-path="url(#terminal-2134602296-line-14)">-airflow</text><text class="terminal-2134602296-r5" x="134.2" y="361.6" textLength="85.4" clip-path="url(#termin [...]
+</text><text class="terminal-2134602296-r4" x="0" y="386" textLength="12.2" clip-path="url(#terminal-2134602296-line-15)">│</text><text class="terminal-2134602296-r5" x="24.4" y="386" textLength="12.2" clip-path="url(#terminal-2134602296-line-15)">-</text><text class="terminal-2134602296-r5" x="36.6" y="386" textLength="48.8" clip-path="url(#terminal-2134602296-line-15)">-use</text><text class="terminal-2134602296-r5" x="85.4" y="386" textLength="231.8" clip-path="url(#terminal-213460229 [...]
+</text><text class="terminal-2134602296-r4" x="0" y="410.4" textLength="12.2" clip-path="url(#terminal-2134602296-line-16)">│</text><text class="terminal-2134602296-r2" x="451.4" y="410.4" textLength="988.2" clip-path="url(#terminal-2134602296-line-16)">when entering breeze.                                   [...]
+</text><text class="terminal-2134602296-r4" x="0" y="434.8" textLength="12.2" clip-path="url(#terminal-2134602296-line-17)">│</text><text class="terminal-2134602296-r5" x="24.4" y="434.8" textLength="12.2" clip-path="url(#terminal-2134602296-line-17)">-</text><text class="terminal-2134602296-r5" x="36.6" y="434.8" textLength="97.6" clip-path="url(#terminal-2134602296-line-17)">-package</text><text class="terminal-2134602296-r5" x="134.2" y="434.8" textLength="85.4" clip-path="url(#termin [...]
+</text><text class="terminal-2134602296-r4" x="0" y="459.2" textLength="12.2" clip-path="url(#terminal-2134602296-line-18)">│</text><text class="terminal-2134602296-r4" x="451.4" y="459.2" textLength="658.8" clip-path="url(#terminal-2134602296-line-18)">[default: wheel]                                    & [...]
+</text><text class="terminal-2134602296-r4" x="0" y="483.6" textLength="12.2" clip-path="url(#terminal-2134602296-line-19)">│</text><text class="terminal-2134602296-r5" x="24.4" y="483.6" textLength="12.2" clip-path="url(#terminal-2134602296-line-19)">-</text><text class="terminal-2134602296-r5" x="36.6" y="483.6" textLength="61" clip-path="url(#terminal-2134602296-line-19)">-skip</text><text class="terminal-2134602296-r5" x="97.6" y="483.6" textLength="146.4" clip-path="url(#terminal-21 [...]
+</text><text class="terminal-2134602296-r4" x="0" y="508" textLength="12.2" clip-path="url(#terminal-2134602296-line-20)">│</text><text class="terminal-2134602296-r5" x="24.4" y="508" textLength="12.2" clip-path="url(#terminal-2134602296-line-20)">-</text><text class="terminal-2134602296-r5" x="36.6" y="508" textLength="73.2" clip-path="url(#terminal-2134602296-line-20)">-debug</text><text class="terminal-2134602296-r2" x="451.4" y="508" textLength="878.4" clip-path="url(#terminal-213460 [...]
+</text><text class="terminal-2134602296-r4" x="0" y="532.4" textLength="1464" clip-path="url(#terminal-2134602296-line-21)">╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</text><text class="terminal-2134602296-r2" x="1464" y="532.4" textLength="12.2" clip-path="url(#terminal-2134602296-line-21)">
+</text><text class="terminal-2134602296-r4" x="0" y="556.8" textLength="24.4" clip-path="url(#terminal-2134602296-line-22)">â•─</text><text class="terminal-2134602296-r4" x="24.4" y="556.8" textLength="1415.2" clip-path="url(#terminal-2134602296-line-22)"> Options â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€</text><text class="terminal-2134602296-r4" x="1439.6" y="556.8" textLength="24.4" clip-path="url(#terminal-213 [...]
+</text><text class="terminal-2134602296-r4" x="0" y="581.2" textLength="12.2" clip-path="url(#terminal-2134602296-line-23)">│</text><text class="terminal-2134602296-r5" x="24.4" y="581.2" textLength="12.2" clip-path="url(#terminal-2134602296-line-23)">-</text><text class="terminal-2134602296-r5" x="36.6" y="581.2" textLength="97.6" clip-path="url(#terminal-2134602296-line-23)">-verbose</text><text class="terminal-2134602296-r7" x="280.6" y="581.2" textLength="24.4" clip-path="url(#termin [...]
+</text><text class="terminal-2134602296-r4" x="0" y="605.6" textLength="12.2" clip-path="url(#terminal-2134602296-line-24)">│</text><text class="terminal-2134602296-r5" x="24.4" y="605.6" textLength="12.2" clip-path="url(#terminal-2134602296-line-24)">-</text><text class="terminal-2134602296-r5" x="36.6" y="605.6" textLength="48.8" clip-path="url(#terminal-2134602296-line-24)">-dry</text><text class="terminal-2134602296-r5" x="85.4" y="605.6" textLength="48.8" clip-path="url(#terminal-21 [...]
+</text><text class="terminal-2134602296-r4" x="0" y="630" textLength="12.2" clip-path="url(#terminal-2134602296-line-25)">│</text><text class="terminal-2134602296-r5" x="24.4" y="630" textLength="12.2" clip-path="url(#terminal-2134602296-line-25)">-</text><text class="terminal-2134602296-r5" x="36.6" y="630" textLength="85.4" clip-path="url(#terminal-2134602296-line-25)">-github</text><text class="terminal-2134602296-r5" x="122" y="630" textLength="134.2" clip-path="url(#terminal-2134602 [...]
+</text><text class="terminal-2134602296-r4" x="0" y="654.4" textLength="12.2" clip-path="url(#terminal-2134602296-line-26)">│</text><text class="terminal-2134602296-r5" x="24.4" y="654.4" textLength="12.2" clip-path="url(#terminal-2134602296-line-26)">-</text><text class="terminal-2134602296-r5" x="36.6" y="654.4" textLength="61" clip-path="url(#terminal-2134602296-line-26)">-help</text><text class="terminal-2134602296-r7" x="280.6" y="654.4" textLength="24.4" clip-path="url(#terminal-21 [...]
+</text><text class="terminal-2134602296-r4" x="0" y="678.8" textLength="1464" clip-path="url(#terminal-2134602296-line-27)">╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</text><text class="terminal-2134602296-r2" x="1464" y="678.8" textLength="12.2" clip-path="url(#terminal-2134602296-line-27)">
</text>
</g>
</g>
diff --git a/newsfragments/24399.significant.rst b/newsfragments/24399.significant.rst
new file mode 100644
index 0000000000..7f1833a8e8
--- /dev/null
+++ b/newsfragments/24399.significant.rst
@@ -0,0 +1,31 @@
+We've upgraded Flask Application Builder to a major version 4.*.
+
+Flask Application Builder is one of the important components of Airflow Webserver, as
+it uses a lof of dependencies that are essential to run the webserver and integrate it
+in enterprise environments - especially authentication.
+
+The FAB 4.* upgrades a number of dependencies to major releases, which upgrades them to versions
+that have a number of security issues fixed. A lot of tests were performed to bring the dependencies
+in a backwards-compatible way, however the dependencies themselves implement breaking changes in their
+internals so it might be that some of those changes might impact the users in case they are using the
+libraries for their onw purposes.
+
+One important change that you likely will need to apply to Oauth configuration is to add
+``server_metadata_url`` or ``jwks_uri`` and you can read about it more
+in `this issue <https://github.com/dpgaspar/Flask-AppBuilder/issues/1861>`_.
+
+Here is the list of breaking changes in dependencies that comes together with FAB 4:
+
+* Flask from 1.X to 2.X `breaking changes <https://flask.palletsprojects.com/en/2.0.x/changes/#version-2-0-0>`_
+
+* flask-jwt-extended 3.X to 4.X `breaking changes: <https://flask-jwt-extended.readthedocs.io/en/stable/v4_upgrade_guide/>`_
+
+* Jinja2 2.X to 3.X `breaking changes: <https://jinja.palletsprojects.com/en/3.0.x/changes/#version-3-0-0>`_
+
+* Werkzeug 1.X to 2.X `breaking changes <https://werkzeug.palletsprojects.com/en/2.0.x/changes/#version-2-0-0>`_
+
+* pyJWT 1.X to 2.X `breaking changes: <https://pyjwt.readthedocs.io/en/stable/changelog.html#v2-0-0>`_
+
+* Click 7.X to 8.X `breaking changes: <https://click.palletsprojects.com/en/8.0.x/changes/#version-8-0-0>`_
+
+* itsdangerous 1.X to 2.X `breaking changes <https://github.com/pallets/itsdangerous/blob/main/CHANGES.rst#version-200>`_
diff --git a/scripts/ci/docker-compose/_docker.env b/scripts/ci/docker-compose/_docker.env
index 4edc849b57..b33cfea360 100644
--- a/scripts/ci/docker-compose/_docker.env
+++ b/scripts/ci/docker-compose/_docker.env
@@ -59,6 +59,7 @@ RUN_TESTS
LIST_OF_INTEGRATION_TESTS_TO_RUN
RUN_SYSTEM_TESTS
START_AIRFLOW
+SKIP_CONSTRAINTS
SKIP_ENVIRONMENT_INITIALIZATION
SKIP_SSH_SETUP
TEST_TYPE
diff --git a/scripts/ci/docker-compose/base.yml b/scripts/ci/docker-compose/base.yml
index 48e4d3df96..c1285eda88 100644
--- a/scripts/ci/docker-compose/base.yml
+++ b/scripts/ci/docker-compose/base.yml
@@ -72,6 +72,7 @@ services:
- LIST_OF_INTEGRATION_TESTS_TO_RUN=${LIST_OF_INTEGRATION_TESTS_TO_RUN}
- RUN_SYSTEM_TESTS=${RUN_SYSTEM_TESTS}
- START_AIRFLOW=${START_AIRFLOW}
+ - SKIP_CONSTRAINTS=${SKIP_CONSTRAINTS}
- SKIP_ENVIRONMENT_INITIALIZATION=${SKIP_ENVIRONMENT_INITIALIZATION}
- SKIP_SSH_SETUP=${SKIP_SSH_SETUP}
- TEST_TYPE=${TEST_TYPE}
diff --git a/scripts/ci/docker-compose/devcontainer.env b/scripts/ci/docker-compose/devcontainer.env
index 1c4b27b36a..ae51b20443 100644
--- a/scripts/ci/docker-compose/devcontainer.env
+++ b/scripts/ci/docker-compose/devcontainer.env
@@ -57,6 +57,7 @@ RUN_TESTS="false"
LIST_OF_INTEGRATION_TESTS_TO_RUN=""
RUN_SYSTEM_TESTS=""
START_AIRFLOW="false"
+SKIP_CONSTRAINTS="false"
SKIP_SSH_SETUP="true"
SKIP_ENVIRONMENT_INITIALIZATION="false"
TEST_TYPE=
diff --git a/scripts/ci/pre_commit/pre_commit_check_2_2_compatibility.py b/scripts/ci/pre_commit/pre_commit_check_2_2_compatibility.py
index 8d72c251d5..d956202907 100755
--- a/scripts/ci/pre_commit/pre_commit_check_2_2_compatibility.py
+++ b/scripts/ci/pre_commit/pre_commit_check_2_2_compatibility.py
@@ -35,6 +35,7 @@ errors: List[str] = []
TRY_NUM_MATCHER = re.compile(r".*context.*\[[\"']try_number[\"']].*")
GET_MANDATORY_MATCHER = re.compile(r".*conf\.get_mandatory_value")
+GET_AIRFLOW_APP_MATCHER = re.compile(r".*get_airflow_app\(\)")
def _check_file(_file: Path):
@@ -45,39 +46,48 @@ def _check_file(_file: Path):
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"
+ "(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"
+ "[yellow]When you use XCom.get_value( in providers, it should be in the form:[/]\n\n"
+ "if ti_key is not None:\n"
+ " value = XCom.get_value(...., ti_key=ti_key)\n\n"
+ "See: https://airflow.apache.org/docs/apache-airflow-providers/"
+ "howto/create-update-providers.html#using-providers-with-dynamic-task-mapping\n"
)
if "ti.map_index" in line:
errors.append(
f"[red]In {_file}:{index} there is a forbidden construct "
- f"(Airflow 2.3+ only):[/]\n\n"
+ "(Airflow 2.3+ only):[/]\n\n"
f"{lines[index]}\n\n"
- f"[yellow]You should not use map_index field in providers "
- f"as it is not available in Airflow 2.2[/]"
+ "[yellow]You should not use map_index field in providers "
+ "as it is only available in Airflow 2.3+[/]"
)
if TRY_NUM_MATCHER.match(line):
errors.append(
f"[red]In {_file}:{index} there is a forbidden construct "
- f"(Airflow 2.3+ only):[/]\n\n"
+ "(Airflow 2.3+ only):[/]\n\n"
f"{lines[index]}\n\n"
- f"[yellow]You should not expect try_number field for context in providers "
- f"as it is not available in Airflow 2.2[/]"
+ "[yellow]You should not expect try_number field for context in providers "
+ "as it is only available in Airflow 2.3+[/]"
)
if GET_MANDATORY_MATCHER.match(line):
errors.append(
f"[red]In {_file}:{index} there is a forbidden construct "
- f"(Airflow 2.3+ only):[/]\n\n"
+ "(Airflow 2.3+ only):[/]\n\n"
f"{lines[index]}\n\n"
- f"[yellow]You should not use conf.get_mandatory_value "
- f"as it is not available in Airflow 2.2[/]"
+ "[yellow]You should not use conf.get_mandatory_value in providers "
+ "as it is only available in Airflow 2.3+[/]"
+ )
+
+ if GET_AIRFLOW_APP_MATCHER.match(line):
+ errors.append(
+ f"[red]In {_file}:{index} there is a forbidden construct "
+ "(Airflow 2.4+ only):[/]\n\n"
+ f"{lines[index]}\n\n"
+ "[yellow]You should not use airflow.utils.airflow_flask_app.get_airflow_app() in providers "
+ "as it is not available in Airflow 2.4+. Use current_app instead.[/]"
)
diff --git a/scripts/docker/entrypoint_ci.sh b/scripts/docker/entrypoint_ci.sh
index f5198a556c..2994604fc9 100755
--- a/scripts/docker/entrypoint_ci.sh
+++ b/scripts/docker/entrypoint_ci.sh
@@ -94,9 +94,15 @@ if [[ ${SKIP_ENVIRONMENT_INITIALIZATION=} != "true" ]]; then
echo "${COLOR_BLUE}Uninstalling airflow and providers"
echo
uninstall_airflow_and_providers
- echo "${COLOR_BLUE}Install airflow from wheel package with extras: '${AIRFLOW_EXTRAS}' and constraints reference ${AIRFLOW_CONSTRAINTS_REFERENCE}.${COLOR_RESET}"
- echo
- install_airflow_from_wheel "${AIRFLOW_EXTRAS}" "${AIRFLOW_CONSTRAINTS_REFERENCE}"
+ if [[ ${SKIP_CONSTRAINTS,,=} == "true" ]]; then
+ echo "${COLOR_BLUE}Install airflow from wheel package with extras: '${AIRFLOW_EXTRAS}' with no constraints.${COLOR_RESET}"
+ echo
+ install_airflow_from_wheel "${AIRFLOW_EXTRAS}" "none"
+ else
+ echo "${COLOR_BLUE}Install airflow from wheel package with extras: '${AIRFLOW_EXTRAS}' and constraints reference ${AIRFLOW_CONSTRAINTS_REFERENCE}.${COLOR_RESET}"
+ echo
+ install_airflow_from_wheel "${AIRFLOW_EXTRAS}" "${AIRFLOW_CONSTRAINTS_REFERENCE}"
+ fi
uninstall_providers
elif [[ ${USE_AIRFLOW_VERSION} == "sdist" ]]; then
echo
@@ -104,9 +110,15 @@ if [[ ${SKIP_ENVIRONMENT_INITIALIZATION=} != "true" ]]; then
echo
uninstall_airflow_and_providers
echo
- echo "${COLOR_BLUE}Install airflow from sdist package with extras: '${AIRFLOW_EXTRAS}' and constraints reference ${AIRFLOW_CONSTRAINTS_REFERENCE}.${COLOR_RESET}"
- echo
- install_airflow_from_sdist "${AIRFLOW_EXTRAS}" "${AIRFLOW_CONSTRAINTS_REFERENCE}"
+ if [[ ${SKIP_CONSTRAINTS,,=} == "true" ]]; then
+ echo "${COLOR_BLUE}Install airflow from sdist package with extras: '${AIRFLOW_EXTRAS}' with no constraints.${COLOR_RESET}"
+ echo
+ install_airflow_from_sdist "${AIRFLOW_EXTRAS}" "none"
+ else
+ echo "${COLOR_BLUE}Install airflow from sdist package with extras: '${AIRFLOW_EXTRAS}' and constraints reference ${AIRFLOW_CONSTRAINTS_REFERENCE}.${COLOR_RESET}"
+ echo
+ install_airflow_from_sdist "${AIRFLOW_EXTRAS}" "${AIRFLOW_CONSTRAINTS_REFERENCE}"
+ fi
uninstall_providers
else
echo
@@ -114,9 +126,15 @@ if [[ ${SKIP_ENVIRONMENT_INITIALIZATION=} != "true" ]]; then
echo
uninstall_airflow_and_providers
echo
- echo "${COLOR_BLUE}Install released airflow from PyPI with extras: '${AIRFLOW_EXTRAS}' and constraints reference ${AIRFLOW_CONSTRAINTS_REFERENCE}.${COLOR_RESET}"
- echo
- install_released_airflow_version "${USE_AIRFLOW_VERSION}" "${AIRFLOW_CONSTRAINTS_REFERENCE}"
+ if [[ ${SKIP_CONSTRAINTS,,=} == "true" ]]; then
+ echo "${COLOR_BLUE}Install released airflow from PyPI with extras: '${AIRFLOW_EXTRAS}' with no constraints.${COLOR_RESET}"
+ echo
+ install_released_airflow_version "${USE_AIRFLOW_VERSION}" "none"
+ else
+ echo "${COLOR_BLUE}Install released airflow from PyPI with extras: '${AIRFLOW_EXTRAS}' and constraints reference ${AIRFLOW_CONSTRAINTS_REFERENCE}.${COLOR_RESET}"
+ echo
+ install_released_airflow_version "${USE_AIRFLOW_VERSION}" "${AIRFLOW_CONSTRAINTS_REFERENCE}"
+ fi
fi
if [[ ${USE_PACKAGES_FROM_DIST=} == "true" ]]; then
echo
diff --git a/scripts/in_container/_in_container_utils.sh b/scripts/in_container/_in_container_utils.sh
index d6a637e5c3..66f2e6b083 100644
--- a/scripts/in_container/_in_container_utils.sh
+++ b/scripts/in_container/_in_container_utils.sh
@@ -224,8 +224,12 @@ function install_airflow_from_wheel() {
>&2 echo
exit 4
fi
- pip install "${airflow_package}${extras}" --constraint \
- "https://raw.githubusercontent.com/apache/airflow/${constraints_reference}/constraints-${PYTHON_MAJOR_MINOR_VERSION}.txt"
+ if [[ ${constraints_reference} == "none" ]]; then
+ pip install "${airflow_package}${extras}"
+ else
+ pip install "${airflow_package}${extras}" --constraint \
+ "https://raw.githubusercontent.com/apache/airflow/${constraints_reference}/constraints-${PYTHON_MAJOR_MINOR_VERSION}.txt"
+ fi
}
function install_airflow_from_sdist() {
@@ -250,8 +254,12 @@ function install_airflow_from_sdist() {
>&2 echo
exit 4
fi
- pip install "${airflow_package}${extras}" --constraint \
- "https://raw.githubusercontent.com/apache/airflow/${constraints_reference}/constraints-${PYTHON_MAJOR_MINOR_VERSION}.txt"
+ if [[ ${constraints_reference} == "none" ]]; then
+ pip install "${airflow_package}${extras}"
+ else
+ pip install "${airflow_package}${extras}" --constraint \
+ "https://raw.githubusercontent.com/apache/airflow/${constraints_reference}/constraints-${PYTHON_MAJOR_MINOR_VERSION}.txt"
+ fi
}
function uninstall_airflow() {
@@ -278,17 +286,20 @@ function uninstall_airflow_and_providers() {
function install_released_airflow_version() {
local version="${1}"
- echo
- echo "Installing released ${version} version of airflow with extras: ${AIRFLOW_EXTRAS} and constraints constraints-${version}"
- echo
+ local constraints_reference
+ constraints_reference="${2:-}"
rm -rf "${AIRFLOW_SOURCES}"/*.egg-info
if [[ ${AIRFLOW_EXTRAS} != "" ]]; then
BRACKETED_AIRFLOW_EXTRAS="[${AIRFLOW_EXTRAS}]"
else
BRACKETED_AIRFLOW_EXTRAS=""
fi
- pip install "apache-airflow${BRACKETED_AIRFLOW_EXTRAS}==${version}" \
- --constraint "https://raw.githubusercontent.com/${CONSTRAINTS_GITHUB_REPOSITORY}/constraints-${version}/constraints-${PYTHON_MAJOR_MINOR_VERSION}.txt"
+ if [[ ${constraints_reference} == "none" ]]; then
+ pip install "${airflow_package}${extras}"
+ else
+ pip install "apache-airflow${BRACKETED_AIRFLOW_EXTRAS}==${version}" \
+ --constraint "https://raw.githubusercontent.com/${CONSTRAINTS_GITHUB_REPOSITORY}/constraints-${version}/constraints-${PYTHON_MAJOR_MINOR_VERSION}.txt"
+ fi
}
function install_local_airflow_with_eager_upgrade() {
diff --git a/setup.cfg b/setup.cfg
index 1512a6201c..a32326cee2 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -101,50 +101,31 @@ install_requires =
cryptography>=0.9.3
deprecated>=1.2.13
dill>=0.2.2
- # Flask and all related libraries are limited to below 2.0.0 because we expect it to introduce
- # Serious breaking changes. Flask 2.0 has been introduced in May 2021 and 2.0.2 version is available
- # now (Feb 2022): TODO: we should attempt to migrate to Flask 2 and all below flask libraries soon.
- flask>=1.1.0, <2.0
+ flask>=2.0
# We are tightly coupled with FAB version because we vendored in part of FAB code related to security manager
# This is done as part of preparation to removing FAB as dependency, but we are not ready for it yet
# Every time we update FAB version here, please make sure that you review the classes and models in
# `airflow/www/fab_security` with their upstream counterparts. In particular, make sure any breaking changes,
# for example any new methods, are accounted for.
- flask-appbuilder==3.4.5
- flask-caching>=1.5.0, <2.0.0
- flask-login>=0.3, <0.5
- # Strict upper-bound on the latest release of flask-session,
- # as any schema changes will require a migration.
- flask-session>=0.3.1, <=0.4.0
- flask-wtf>=0.14.3, <0.15
+ flask-appbuilder==4.1.1
+ flask-caching>=1.5.0
+ flask-login>=0.5
+ flask-session>=0.4.0
+ flask-wtf>=0.14.3
graphviz>=0.12
gunicorn>=20.1.0
httpx
importlib_metadata>=1.7;python_version<"3.9"
importlib_resources>=5.2;python_version<"3.9"
- # Logging is broken with itsdangerous > 2 - likely due to changed serializing support
- # https://itsdangerous.palletsprojects.com/en/2.0.x/changes/#version-2-0-0
- # itsdangerous 2 has been released in May 2020
- # TODO: we should attempt to upgrade to line 2 of itsdangerous
- itsdangerous>=1.1.0, <2.0
- # Jinja2 3.1 will remove the 'autoescape' and 'with' extensions, which would
- # break Flask 1.x, so we limit this for future compatibility. Remove this
- # when bumping Flask to >=2.
- jinja2>=2.10.1,<3.1
- # Because connexion upper-bound is 5.0.0 and we depend on connexion,
- # we pin to the same upper-bound as connexion.
- jsonschema>=3.2.0, <5.0
+ itsdangerous>=2.0
+ jinja2>=2.10.1
+ jsonschema>=3.2.0
lazy-object-proxy
linkify-it-py>=2.0.0
lockfile>=0.12.2
markdown>=3.0
- # Markupsafe 2.1.0 breaks with error: import name 'soft_unicode' from 'markupsafe'.
- # This should be removed when either this issue is closed:
- # https://github.com/pallets/markupsafe/issues/284
- # or when we will be able to upgrade JINJA to newer version (currently limited due to Flask and
- # Flask Application Builder)
markdown-it-py>=2.1.0
- markupsafe>=1.1.1,<2.1.0
+ markupsafe>=1.1.1
marshmallow-oneofschema>=2.0.1
mdit-py-plugins>=0.3.0
packaging>=14.0
@@ -153,8 +134,7 @@ install_requires =
pluggy>=1.0
psutil>=4.2.0
pygments>=2.0.1
- # python daemon crashes with 'socket operation on non-socket' for python 3.8+ in version < 2.2.4
- # https://pagure.io/python-daemon/issue/34
+ pyjwt>=2.0.0
python-daemon>=2.2.4
python-dateutil>=2.3
python-nvd3>=0.15.0
@@ -172,10 +152,7 @@ install_requires =
termcolor>=1.1.0
typing-extensions>=3.7.4
unicodecsv>=0.14.1
- # Werkzeug is known to cause breaking changes and it is very closely tied with FlaskAppBuilder and other
- # Flask dependencies and the limit to 1.* line should be reviewed when we upgrade Flask and remove
- # FlaskAppBuilder.
- werkzeug~=1.0, >=1.0.1
+ werkzeug>=2.0
[options.packages.find]
include =
diff --git a/setup.py b/setup.py
index 3edaf59c6a..c52a682f66 100644
--- a/setup.py
+++ b/setup.py
@@ -618,16 +618,6 @@ devel_only = [
'flake8-implicit-str-concat',
'flaky',
'freezegun',
- # Github3 version 3.1.2 requires PyJWT>=2.3.0 which clashes with Flask App Builder where PyJWT is <2.0.0
- # Actually GitHub3.1.0 already introduced PyJWT>=2.3.0 but so far `pip` was able to resolve it without
- # getting into a long backtracking loop and figure out that github3 3.0.0 version is the right version
- # similarly limiting it to 3.1.2 causes pip not to enter the backtracking loop. Apparently when there
- # are 3 versions with PyJWT>=2.3.0 (3.1.0, 3.1.1 an 3.1.2) pip enters into backtrack loop and fails
- # to resolve that github3 3.0.0 is the right version to use.
- # This limitation could be removed if PyJWT limitation < 2.0.0 is dropped from FAB or when
- # pip resolution is improved to handle the case. The issue which describes this PIP behaviour
- # and hopefully allowing to improve it is tracked in https://github.com/pypa/pip/issues/10924
- 'github3.py<3.1.0',
'gitpython',
'ipdb',
'jira',
@@ -658,7 +648,7 @@ devel_only = [
'qds-sdk>=1.9.6',
'pytest-httpx',
'requests_mock',
- 'rich_click',
+ 'rich-click>=1.5',
'semver',
'towncrier',
'twine',
diff --git a/tests/api_connexion/endpoints/test_dag_endpoint.py b/tests/api_connexion/endpoints/test_dag_endpoint.py
index d95d4c3854..09ef3c28ae 100644
--- a/tests/api_connexion/endpoints/test_dag_endpoint.py
+++ b/tests/api_connexion/endpoints/test_dag_endpoint.py
@@ -19,12 +19,10 @@ import unittest.mock
from datetime import datetime
import pytest
-from itsdangerous import URLSafeSerializer
from parameterized import parameterized
from airflow import DAG
from airflow.api_connexion.exceptions import EXCEPTIONS_LINK_MAP
-from airflow.configuration import conf
from airflow.models import DagBag, DagModel
from airflow.models.serialized_dag import SerializedDagModel
from airflow.operators.empty import EmptyOperator
@@ -34,8 +32,12 @@ from tests.test_utils.api_connexion_utils import assert_401, create_user, delete
from tests.test_utils.config import conf_vars
from tests.test_utils.db import clear_db_dags, clear_db_runs, clear_db_serialized_dags
-SERIALIZER = URLSafeSerializer(conf.get('webserver', 'secret_key'))
-FILE_TOKEN = SERIALIZER.dumps(__file__)
+
+@pytest.fixture()
+def current_file_token(url_safe_serializer) -> str:
+ return url_safe_serializer.dumps(__file__)
+
+
DAG_ID = "test_dag"
TASK_ID = "op1"
DAG2_ID = "test_dag2"
@@ -246,7 +248,7 @@ class TestGetDag(TestDagEndpoint):
class TestGetDagDetails(TestDagEndpoint):
- def test_should_respond_200(self):
+ def test_should_respond_200(self, current_file_token):
response = self.client.get(
f"/api/v1/dags/{self.dag_id}/details", environ_overrides={'REMOTE_USER': "test"}
)
@@ -262,7 +264,7 @@ class TestGetDagDetails(TestDagEndpoint):
"description": None,
"doc_md": "details",
"fileloc": __file__,
- "file_token": FILE_TOKEN,
+ "file_token": current_file_token,
"is_paused": None,
"is_active": None,
"is_subdag": False,
@@ -294,7 +296,7 @@ class TestGetDagDetails(TestDagEndpoint):
}
assert response.json == expected
- def test_should_response_200_with_doc_md_none(self):
+ def test_should_response_200_with_doc_md_none(self, current_file_token):
response = self.client.get(
f"/api/v1/dags/{self.dag2_id}/details", environ_overrides={'REMOTE_USER': "test"}
)
@@ -310,7 +312,7 @@ class TestGetDagDetails(TestDagEndpoint):
"description": None,
"doc_md": None,
"fileloc": __file__,
- "file_token": FILE_TOKEN,
+ "file_token": current_file_token,
"is_paused": None,
"is_active": None,
"is_subdag": False,
@@ -335,7 +337,7 @@ class TestGetDagDetails(TestDagEndpoint):
}
assert response.json == expected
- def test_should_response_200_for_null_start_date(self):
+ def test_should_response_200_for_null_start_date(self, current_file_token):
response = self.client.get(
f"/api/v1/dags/{self.dag3_id}/details", environ_overrides={'REMOTE_USER': "test"}
)
@@ -351,7 +353,7 @@ class TestGetDagDetails(TestDagEndpoint):
"description": None,
"doc_md": None,
"fileloc": __file__,
- "file_token": FILE_TOKEN,
+ "file_token": current_file_token,
"is_paused": None,
"is_active": None,
"is_subdag": False,
@@ -376,7 +378,7 @@ class TestGetDagDetails(TestDagEndpoint):
}
assert response.json == expected
- def test_should_respond_200_serialized(self):
+ def test_should_respond_200_serialized(self, current_file_token):
# Get the dag out of the dagbag before we patch it to an empty one
SerializedDagModel.write_dag(self.app.dag_bag.get_dag(self.dag_id))
@@ -395,7 +397,7 @@ class TestGetDagDetails(TestDagEndpoint):
"description": None,
"doc_md": "details",
"fileloc": __file__,
- "file_token": FILE_TOKEN,
+ "file_token": current_file_token,
"is_paused": None,
"is_active": None,
"is_subdag": False,
@@ -449,7 +451,7 @@ class TestGetDagDetails(TestDagEndpoint):
'description': None,
'doc_md': 'details',
'fileloc': __file__,
- "file_token": FILE_TOKEN,
+ "file_token": current_file_token,
'is_paused': None,
"is_active": None,
'is_subdag': False,
@@ -496,7 +498,7 @@ class TestGetDagDetails(TestDagEndpoint):
class TestGetDags(TestDagEndpoint):
@provide_session
- def test_should_respond_200(self, session):
+ def test_should_respond_200(self, session, url_safe_serializer):
self._create_dag_models(2)
self._create_deactivated_dag()
@@ -504,8 +506,8 @@ class TestGetDags(TestDagEndpoint):
assert len(dags_query.all()) == 3
response = self.client.get("api/v1/dags", environ_overrides={'REMOTE_USER': "test"})
- file_token = SERIALIZER.dumps("/tmp/dag_1.py")
- file_token2 = SERIALIZER.dumps("/tmp/dag_2.py")
+ file_token = url_safe_serializer.dumps("/tmp/dag_1.py")
+ file_token2 = url_safe_serializer.dumps("/tmp/dag_2.py")
assert response.status_code == 200
assert {
@@ -576,11 +578,11 @@ class TestGetDags(TestDagEndpoint):
"total_entries": 2,
} == response.json
- def test_only_active_true_returns_active_dags(self):
+ def test_only_active_true_returns_active_dags(self, url_safe_serializer):
self._create_dag_models(1)
self._create_deactivated_dag()
response = self.client.get("api/v1/dags?only_active=True", environ_overrides={'REMOTE_USER': "test"})
- file_token = SERIALIZER.dumps("/tmp/dag_1.py")
+ file_token = url_safe_serializer.dumps("/tmp/dag_1.py")
assert response.status_code == 200
assert {
"dags": [
@@ -619,12 +621,12 @@ class TestGetDags(TestDagEndpoint):
"total_entries": 1,
} == response.json
- def test_only_active_false_returns_all_dags(self):
+ def test_only_active_false_returns_all_dags(self, url_safe_serializer):
self._create_dag_models(1)
self._create_deactivated_dag()
response = self.client.get("api/v1/dags?only_active=False", environ_overrides={'REMOTE_USER': "test"})
- file_token = SERIALIZER.dumps("/tmp/dag_1.py")
- file_token_2 = SERIALIZER.dumps("/tmp/dag_del_1.py")
+ file_token = url_safe_serializer.dumps("/tmp/dag_1.py")
+ file_token_2 = url_safe_serializer.dumps("/tmp/dag_del_1.py")
assert response.status_code == 200
assert {
"dags": [
@@ -819,10 +821,8 @@ class TestGetDags(TestDagEndpoint):
class TestPatchDag(TestDagEndpoint):
-
- file_token = SERIALIZER.dumps("/tmp/dag_1.py")
-
- def test_should_respond_200_on_patch_is_paused(self):
+ def test_should_respond_200_on_patch_is_paused(self, url_safe_serializer):
+ file_token = url_safe_serializer.dumps("/tmp/dag_1.py")
dag_model = self._create_dag_model()
response = self.client.patch(
f"/api/v1/dags/{dag_model.dag_id}",
@@ -832,12 +832,11 @@ class TestPatchDag(TestDagEndpoint):
environ_overrides={'REMOTE_USER': "test"},
)
assert response.status_code == 200
-
expected_response = {
"dag_id": "TEST_DAG_1",
"description": None,
"fileloc": "/tmp/dag_1.py",
- "file_token": self.file_token,
+ "file_token": file_token,
"is_paused": False,
"is_active": False,
"is_subdag": False,
@@ -918,7 +917,8 @@ class TestPatchDag(TestDagEndpoint):
assert_401(response)
- def test_should_respond_200_with_update_mask(self):
+ def test_should_respond_200_with_update_mask(self, url_safe_serializer):
+ file_token = url_safe_serializer.dumps("/tmp/dag_1.py")
dag_model = self._create_dag_model()
payload = {
"is_paused": False,
@@ -934,7 +934,7 @@ class TestPatchDag(TestDagEndpoint):
"dag_id": "TEST_DAG_1",
"description": None,
"fileloc": "/tmp/dag_1.py",
- "file_token": self.file_token,
+ "file_token": file_token,
"is_paused": False,
"is_active": False,
"is_subdag": False,
@@ -1006,12 +1006,10 @@ class TestPatchDag(TestDagEndpoint):
class TestPatchDags(TestDagEndpoint):
-
- file_token = SERIALIZER.dumps("/tmp/dag_1.py")
- file_token2 = SERIALIZER.dumps("/tmp/dag_2.py")
-
@provide_session
- def test_should_respond_200_on_patch_is_paused(self, session):
+ def test_should_respond_200_on_patch_is_paused(self, session, url_safe_serializer):
+ file_token = url_safe_serializer.dumps("/tmp/dag_1.py")
+ file_token2 = url_safe_serializer.dumps("/tmp/dag_2.py")
self._create_dag_models(2)
self._create_deactivated_dag()
@@ -1033,7 +1031,7 @@ class TestPatchDags(TestDagEndpoint):
"dag_id": "TEST_DAG_1",
"description": None,
"fileloc": "/tmp/dag_1.py",
- "file_token": self.file_token,
+ "file_token": file_token,
"is_paused": False,
"is_active": True,
"is_subdag": False,
@@ -1064,7 +1062,7 @@ class TestPatchDags(TestDagEndpoint):
"dag_id": "TEST_DAG_2",
"description": None,
"fileloc": "/tmp/dag_2.py",
- "file_token": self.file_token2,
+ "file_token": file_token2,
"is_paused": False,
"is_active": True,
"is_subdag": False,
@@ -1095,7 +1093,8 @@ class TestPatchDags(TestDagEndpoint):
"total_entries": 2,
} == response.json
- def test_only_active_true_returns_active_dags(self):
+ def test_only_active_true_returns_active_dags(self, url_safe_serializer):
+ file_token = url_safe_serializer.dumps("/tmp/dag_1.py")
self._create_dag_models(1)
self._create_deactivated_dag()
response = self.client.patch(
@@ -1112,7 +1111,7 @@ class TestPatchDags(TestDagEndpoint):
"dag_id": "TEST_DAG_1",
"description": None,
"fileloc": "/tmp/dag_1.py",
- "file_token": self.file_token,
+ "file_token": file_token,
"is_paused": False,
"is_active": True,
"is_subdag": False,
@@ -1143,7 +1142,8 @@ class TestPatchDags(TestDagEndpoint):
"total_entries": 1,
} == response.json
- def test_only_active_false_returns_all_dags(self):
+ def test_only_active_false_returns_all_dags(self, url_safe_serializer):
+ file_token = url_safe_serializer.dumps("/tmp/dag_1.py")
self._create_dag_models(1)
self._create_deactivated_dag()
response = self.client.patch(
@@ -1154,7 +1154,7 @@ class TestPatchDags(TestDagEndpoint):
environ_overrides={'REMOTE_USER': "test"},
)
- file_token_2 = SERIALIZER.dumps("/tmp/dag_del_1.py")
+ file_token_2 = url_safe_serializer.dumps("/tmp/dag_del_1.py")
assert response.status_code == 200
assert {
"dags": [
@@ -1162,7 +1162,7 @@ class TestPatchDags(TestDagEndpoint):
"dag_id": "TEST_DAG_1",
"description": None,
"fileloc": "/tmp/dag_1.py",
- "file_token": self.file_token,
+ "file_token": file_token,
"is_paused": False,
"is_active": True,
"is_subdag": False,
@@ -1399,7 +1399,9 @@ class TestPatchDags(TestDagEndpoint):
assert response.status_code == 403
- def test_should_respond_200_and_pause_dags(self):
+ def test_should_respond_200_and_pause_dags(self, url_safe_serializer):
+ file_token = url_safe_serializer.dumps("/tmp/dag_1.py")
+ file_token2 = url_safe_serializer.dumps("/tmp/dag_2.py")
self._create_dag_models(2)
response = self.client.patch(
@@ -1417,7 +1419,7 @@ class TestPatchDags(TestDagEndpoint):
"dag_id": "TEST_DAG_1",
"description": None,
"fileloc": "/tmp/dag_1.py",
- "file_token": self.file_token,
+ "file_token": file_token,
"is_paused": True,
"is_active": True,
"is_subdag": False,
@@ -1448,7 +1450,7 @@ class TestPatchDags(TestDagEndpoint):
"dag_id": "TEST_DAG_2",
"description": None,
"fileloc": "/tmp/dag_2.py",
- "file_token": self.file_token2,
+ "file_token": file_token2,
"is_paused": True,
"is_active": True,
"is_subdag": False,
@@ -1480,9 +1482,10 @@ class TestPatchDags(TestDagEndpoint):
} == response.json
@provide_session
- def test_should_respond_200_and_pause_dag_pattern(self, session):
+ def test_should_respond_200_and_pause_dag_pattern(self, session, url_safe_serializer):
+ file_token = url_safe_serializer.dumps("/tmp/dag_1.py")
self._create_dag_models(10)
- file_token10 = SERIALIZER.dumps("/tmp/dag_10.py")
+ file_token10 = url_safe_serializer.dumps("/tmp/dag_10.py")
response = self.client.patch(
"/api/v1/dags?dag_id_pattern=TEST_DAG_1",
@@ -1499,7 +1502,7 @@ class TestPatchDags(TestDagEndpoint):
"dag_id": "TEST_DAG_1",
"description": None,
"fileloc": "/tmp/dag_1.py",
- "file_token": self.file_token,
+ "file_token": file_token,
"is_paused": True,
"is_active": True,
"is_subdag": False,
diff --git a/tests/api_connexion/endpoints/test_dag_source_endpoint.py b/tests/api_connexion/endpoints/test_dag_source_endpoint.py
index 5fec9f2798..cb8b5a9c11 100644
--- a/tests/api_connexion/endpoints/test_dag_source_endpoint.py
+++ b/tests/api_connexion/endpoints/test_dag_source_endpoint.py
@@ -19,10 +19,8 @@ import os
from typing import Optional
import pytest
-from itsdangerous import URLSafeSerializer
from airflow import DAG
-from airflow.configuration import conf
from airflow.models import DagBag
from airflow.security import permissions
from tests.test_utils.api_connexion_utils import assert_401, create_user, delete_user
@@ -73,15 +71,14 @@ class TestGetSource:
docstring = ast.get_docstring(module)
return docstring
- def test_should_respond_200_text(self):
- serializer = URLSafeSerializer(conf.get('webserver', 'SECRET_KEY'))
+ def test_should_respond_200_text(self, url_safe_serializer):
dagbag = DagBag(dag_folder=EXAMPLE_DAG_FILE)
dagbag.sync_to_db()
first_dag: DAG = next(iter(dagbag.dags.values()))
dag_docstring = self._get_dag_file_docstring(first_dag.fileloc)
- url = f"/api/v1/dagSources/{serializer.dumps(first_dag.fileloc)}"
+ url = f"/api/v1/dagSources/{url_safe_serializer.dumps(first_dag.fileloc)}"
response = self.client.get(
url, headers={"Accept": "text/plain"}, environ_overrides={'REMOTE_USER': "test"}
)
@@ -90,14 +87,13 @@ class TestGetSource:
assert dag_docstring in response.data.decode()
assert 'text/plain' == response.headers['Content-Type']
- def test_should_respond_200_json(self):
- serializer = URLSafeSerializer(conf.get('webserver', 'SECRET_KEY'))
+ def test_should_respond_200_json(self, url_safe_serializer):
dagbag = DagBag(dag_folder=EXAMPLE_DAG_FILE)
dagbag.sync_to_db()
first_dag: DAG = next(iter(dagbag.dags.values()))
dag_docstring = self._get_dag_file_docstring(first_dag.fileloc)
- url = f"/api/v1/dagSources/{serializer.dumps(first_dag.fileloc)}"
+ url = f"/api/v1/dagSources/{url_safe_serializer.dumps(first_dag.fileloc)}"
response = self.client.get(
url, headers={"Accept": 'application/json'}, environ_overrides={'REMOTE_USER': "test"}
)
@@ -106,13 +102,12 @@ class TestGetSource:
assert dag_docstring in response.json['content']
assert 'application/json' == response.headers['Content-Type']
- def test_should_respond_406(self):
- serializer = URLSafeSerializer(conf.get('webserver', 'SECRET_KEY'))
+ def test_should_respond_406(self, url_safe_serializer):
dagbag = DagBag(dag_folder=EXAMPLE_DAG_FILE)
dagbag.sync_to_db()
first_dag: DAG = next(iter(dagbag.dags.values()))
- url = f"/api/v1/dagSources/{serializer.dumps(first_dag.fileloc)}"
+ url = f"/api/v1/dagSources/{url_safe_serializer.dumps(first_dag.fileloc)}"
response = self.client.get(
url, headers={"Accept": 'image/webp'}, environ_overrides={'REMOTE_USER': "test"}
)
@@ -128,27 +123,25 @@ class TestGetSource:
assert 404 == response.status_code
- def test_should_raises_401_unauthenticated(self):
- serializer = URLSafeSerializer(conf.get('webserver', 'SECRET_KEY'))
+ def test_should_raises_401_unauthenticated(self, url_safe_serializer):
dagbag = DagBag(dag_folder=EXAMPLE_DAG_FILE)
dagbag.sync_to_db()
first_dag: DAG = next(iter(dagbag.dags.values()))
response = self.client.get(
- f"/api/v1/dagSources/{serializer.dumps(first_dag.fileloc)}",
+ f"/api/v1/dagSources/{url_safe_serializer.dumps(first_dag.fileloc)}",
headers={"Accept": "text/plain"},
)
assert_401(response)
- def test_should_raise_403_forbidden(self):
- serializer = URLSafeSerializer(conf.get('webserver', 'SECRET_KEY'))
+ def test_should_raise_403_forbidden(self, url_safe_serializer):
dagbag = DagBag(dag_folder=EXAMPLE_DAG_FILE)
dagbag.sync_to_db()
first_dag: DAG = next(iter(dagbag.dags.values()))
response = self.client.get(
- f"/api/v1/dagSources/{serializer.dumps(first_dag.fileloc)}",
+ f"/api/v1/dagSources/{url_safe_serializer.dumps(first_dag.fileloc)}",
headers={"Accept": "text/plain"},
environ_overrides={'REMOTE_USER': "test_no_permissions"},
)
diff --git a/tests/api_connexion/endpoints/test_xcom_endpoint.py b/tests/api_connexion/endpoints/test_xcom_endpoint.py
index 7c4452dc2b..efcba32711 100644
--- a/tests/api_connexion/endpoints/test_xcom_endpoint.py
+++ b/tests/api_connexion/endpoints/test_xcom_endpoint.py
@@ -185,7 +185,7 @@ class TestGetXComEntries(TestXComEndpoint):
response_data = response.json
for xcom_entry in response_data['xcom_entries']:
xcom_entry['timestamp'] = "TIMESTAMP"
- assert response.json == {
+ assert response_data == {
'xcom_entries': [
{
'dag_id': dag_id,
@@ -227,7 +227,7 @@ class TestGetXComEntries(TestXComEndpoint):
response_data = response.json
for xcom_entry in response_data['xcom_entries']:
xcom_entry['timestamp'] = "TIMESTAMP"
- assert response.json == {
+ assert response_data == {
'xcom_entries': [
{
'dag_id': dag_id_1,
@@ -283,7 +283,7 @@ class TestGetXComEntries(TestXComEndpoint):
response_data = response.json
for xcom_entry in response_data['xcom_entries']:
xcom_entry['timestamp'] = "TIMESTAMP"
- assert response.json == {
+ assert response_data == {
'xcom_entries': [
{
'dag_id': dag_id_1,
diff --git a/tests/api_connexion/schemas/test_dag_schema.py b/tests/api_connexion/schemas/test_dag_schema.py
index ca7e04ae89..040ce41f1d 100644
--- a/tests/api_connexion/schemas/test_dag_schema.py
+++ b/tests/api_connexion/schemas/test_dag_schema.py
@@ -15,11 +15,8 @@
# specific language governing permissions and limitations
# under the License.
-import unittest
from datetime import datetime
-from itsdangerous import URLSafeSerializer
-
from airflow import DAG
from airflow.api_connexion.schemas.dag_schema import (
DAGCollection,
@@ -27,174 +24,168 @@ from airflow.api_connexion.schemas.dag_schema import (
DAGDetailSchema,
DAGSchema,
)
-from airflow.configuration import conf
from airflow.models import DagModel, DagTag
-SERIALIZER = URLSafeSerializer(conf.get('webserver', 'SECRET_KEY'))
-
-class TestDagSchema(unittest.TestCase):
- def test_serialize(self):
- dag_model = DagModel(
- dag_id="test_dag_id",
- root_dag_id="test_root_dag_id",
- is_paused=True,
- is_active=True,
- is_subdag=False,
- fileloc="/root/airflow/dags/my_dag.py",
- owners="airflow1,airflow2",
- description="The description",
- schedule_interval="5 4 * * *",
- tags=[DagTag(name="tag-1"), DagTag(name="tag-2")],
- )
- serialized_dag = DAGSchema().dump(dag_model)
+def test_serialize_test_dag_schema(url_safe_serializer):
+ dag_model = DagModel(
+ dag_id="test_dag_id",
+ root_dag_id="test_root_dag_id",
+ is_paused=True,
+ is_active=True,
+ is_subdag=False,
+ fileloc="/root/airflow/dags/my_dag.py",
+ owners="airflow1,airflow2",
+ description="The description",
+ schedule_interval="5 4 * * *",
+ tags=[DagTag(name="tag-1"), DagTag(name="tag-2")],
+ )
+ serialized_dag = DAGSchema().dump(dag_model)
- assert {
- "dag_id": "test_dag_id",
- "description": "The description",
- "fileloc": "/root/airflow/dags/my_dag.py",
- "file_token": SERIALIZER.dumps("/root/airflow/dags/my_dag.py"),
- "is_paused": True,
- "is_active": True,
- "is_subdag": False,
- "owners": ["airflow1", "airflow2"],
- "root_dag_id": "test_root_dag_id",
- "schedule_interval": {"__type": "CronExpression", "value": "5 4 * * *"},
- "tags": [{"name": "tag-1"}, {"name": "tag-2"}],
- 'next_dagrun': None,
- 'has_task_concurrency_limits': True,
- 'next_dagrun_data_interval_start': None,
- 'next_dagrun_data_interval_end': None,
- 'max_active_runs': 16,
- 'next_dagrun_create_after': None,
- 'last_expired': None,
- 'max_active_tasks': 16,
- 'last_pickled': None,
- 'default_view': None,
- 'last_parsed_time': None,
- 'scheduler_lock': None,
- 'timetable_description': None,
- 'has_import_errors': None,
- 'pickle_id': None,
- } == serialized_dag
+ assert {
+ "dag_id": "test_dag_id",
+ "description": "The description",
+ "fileloc": "/root/airflow/dags/my_dag.py",
+ "file_token": url_safe_serializer.dumps("/root/airflow/dags/my_dag.py"),
+ "is_paused": True,
+ "is_active": True,
+ "is_subdag": False,
+ "owners": ["airflow1", "airflow2"],
+ "root_dag_id": "test_root_dag_id",
+ "schedule_interval": {"__type": "CronExpression", "value": "5 4 * * *"},
+ "tags": [{"name": "tag-1"}, {"name": "tag-2"}],
+ 'next_dagrun': None,
+ 'has_task_concurrency_limits': True,
+ 'next_dagrun_data_interval_start': None,
+ 'next_dagrun_data_interval_end': None,
+ 'max_active_runs': 16,
+ 'next_dagrun_create_after': None,
+ 'last_expired': None,
+ 'max_active_tasks': 16,
+ 'last_pickled': None,
+ 'default_view': None,
+ 'last_parsed_time': None,
+ 'scheduler_lock': None,
+ 'timetable_description': None,
+ 'has_import_errors': None,
+ 'pickle_id': None,
+ } == serialized_dag
-class TestDAGCollectionSchema(unittest.TestCase):
- def test_serialize(self):
- dag_model_a = DagModel(dag_id="test_dag_id_a", fileloc="/tmp/a.py")
- dag_model_b = DagModel(dag_id="test_dag_id_b", fileloc="/tmp/a.py")
- schema = DAGCollectionSchema()
- instance = DAGCollection(dags=[dag_model_a, dag_model_b], total_entries=2)
- assert {
- "dags": [
- {
- "dag_id": "test_dag_id_a",
- "description": None,
- "fileloc": "/tmp/a.py",
- "file_token": SERIALIZER.dumps("/tmp/a.py"),
- "is_paused": None,
- "is_subdag": None,
- "is_active": None,
- "owners": [],
- "root_dag_id": None,
- "schedule_interval": None,
- "tags": [],
- 'next_dagrun': None,
- 'has_task_concurrency_limits': True,
- 'next_dagrun_data_interval_start': None,
- 'next_dagrun_data_interval_end': None,
- 'max_active_runs': 16,
- 'next_dagrun_create_after': None,
- 'last_expired': None,
- 'max_active_tasks': 16,
- 'last_pickled': None,
- 'default_view': None,
- 'last_parsed_time': None,
- 'scheduler_lock': None,
- 'timetable_description': None,
- 'has_import_errors': None,
- 'pickle_id': None,
- },
- {
- "dag_id": "test_dag_id_b",
- "description": None,
- "fileloc": "/tmp/a.py",
- "file_token": SERIALIZER.dumps("/tmp/a.py"),
- "is_active": None,
- "is_paused": None,
- "is_subdag": None,
- "owners": [],
- "root_dag_id": None,
- "schedule_interval": None,
- "tags": [],
- 'next_dagrun': None,
- 'has_task_concurrency_limits': True,
- 'next_dagrun_data_interval_start': None,
- 'next_dagrun_data_interval_end': None,
- 'max_active_runs': 16,
- 'next_dagrun_create_after': None,
- 'last_expired': None,
- 'max_active_tasks': 16,
- 'last_pickled': None,
- 'default_view': None,
- 'last_parsed_time': None,
- 'scheduler_lock': None,
- 'timetable_description': None,
- 'has_import_errors': None,
- 'pickle_id': None,
- },
- ],
- "total_entries": 2,
- } == schema.dump(instance)
+def test_serialize_test_dag_collection_schema(url_safe_serializer):
+ dag_model_a = DagModel(dag_id="test_dag_id_a", fileloc="/tmp/a.py")
+ dag_model_b = DagModel(dag_id="test_dag_id_b", fileloc="/tmp/a.py")
+ schema = DAGCollectionSchema()
+ instance = DAGCollection(dags=[dag_model_a, dag_model_b], total_entries=2)
+ assert {
+ "dags": [
+ {
+ "dag_id": "test_dag_id_a",
+ "description": None,
+ "fileloc": "/tmp/a.py",
+ "file_token": url_safe_serializer.dumps("/tmp/a.py"),
+ "is_paused": None,
+ "is_subdag": None,
+ "is_active": None,
+ "owners": [],
+ "root_dag_id": None,
+ "schedule_interval": None,
+ "tags": [],
+ 'next_dagrun': None,
+ 'has_task_concurrency_limits': True,
+ 'next_dagrun_data_interval_start': None,
+ 'next_dagrun_data_interval_end': None,
+ 'max_active_runs': 16,
+ 'next_dagrun_create_after': None,
+ 'last_expired': None,
+ 'max_active_tasks': 16,
+ 'last_pickled': None,
+ 'default_view': None,
+ 'last_parsed_time': None,
+ 'scheduler_lock': None,
+ 'timetable_description': None,
+ 'has_import_errors': None,
+ 'pickle_id': None,
+ },
+ {
+ "dag_id": "test_dag_id_b",
+ "description": None,
+ "fileloc": "/tmp/a.py",
+ "file_token": url_safe_serializer.dumps("/tmp/a.py"),
+ "is_active": None,
+ "is_paused": None,
+ "is_subdag": None,
+ "owners": [],
+ "root_dag_id": None,
+ "schedule_interval": None,
+ "tags": [],
+ 'next_dagrun': None,
+ 'has_task_concurrency_limits': True,
+ 'next_dagrun_data_interval_start': None,
+ 'next_dagrun_data_interval_end': None,
+ 'max_active_runs': 16,
+ 'next_dagrun_create_after': None,
+ 'last_expired': None,
+ 'max_active_tasks': 16,
+ 'last_pickled': None,
+ 'default_view': None,
+ 'last_parsed_time': None,
+ 'scheduler_lock': None,
+ 'timetable_description': None,
+ 'has_import_errors': None,
+ 'pickle_id': None,
+ },
+ ],
+ "total_entries": 2,
+ } == schema.dump(instance)
-class TestDAGDetailSchema:
- def test_serialize(self):
- dag = DAG(
- dag_id="test_dag",
- start_date=datetime(2020, 6, 19),
- doc_md="docs",
- orientation="LR",
- default_view="duration",
- params={"foo": 1},
- tags=['example1', 'example2'],
- )
- schema = DAGDetailSchema()
+def test_serialize_test_dag_detail_schema(url_safe_serializer):
+ dag = DAG(
+ dag_id="test_dag",
+ start_date=datetime(2020, 6, 19),
+ doc_md="docs",
+ orientation="LR",
+ default_view="duration",
+ params={"foo": 1},
+ tags=['example1', 'example2'],
+ )
+ schema = DAGDetailSchema()
- expected = {
- 'catchup': True,
- 'concurrency': 16,
- 'max_active_tasks': 16,
- 'dag_id': 'test_dag',
- 'dag_run_timeout': None,
- 'default_view': 'duration',
- 'description': None,
- 'doc_md': 'docs',
- 'fileloc': __file__,
- "file_token": SERIALIZER.dumps(__file__),
- "is_active": None,
- 'is_paused': None,
- 'is_subdag': False,
- 'orientation': 'LR',
- 'owners': [],
- 'params': {
- 'foo': {
- '__class': 'airflow.models.param.Param',
- 'value': 1,
- 'description': None,
- 'schema': {},
- }
- },
- 'schedule_interval': {'__type': 'TimeDelta', 'days': 1, 'seconds': 0, 'microseconds': 0},
- 'start_date': '2020-06-19T00:00:00+00:00',
- 'tags': [{'name': "example1"}, {'name': "example2"}],
- 'timezone': "Timezone('UTC')",
- 'max_active_runs': 16,
- 'pickle_id': None,
- "end_date": None,
- 'is_paused_upon_creation': None,
- 'render_template_as_native_obj': False,
- }
- obj = schema.dump(dag)
- expected.update({'last_parsed': obj['last_parsed']})
- assert obj == expected
+ expected = {
+ 'catchup': True,
+ 'concurrency': 16,
+ 'max_active_tasks': 16,
+ 'dag_id': 'test_dag',
+ 'dag_run_timeout': None,
+ 'default_view': 'duration',
+ 'description': None,
+ 'doc_md': 'docs',
+ 'fileloc': __file__,
+ "file_token": url_safe_serializer.dumps(__file__),
+ "is_active": None,
+ 'is_paused': None,
+ 'is_subdag': False,
+ 'orientation': 'LR',
+ 'owners': [],
+ 'params': {
+ 'foo': {
+ '__class': 'airflow.models.param.Param',
+ 'value': 1,
+ 'description': None,
+ 'schema': {},
+ }
+ },
+ 'schedule_interval': {'__type': 'TimeDelta', 'days': 1, 'seconds': 0, 'microseconds': 0},
+ 'start_date': '2020-06-19T00:00:00+00:00',
+ 'tags': [{'name': "example1"}, {'name': "example2"}],
+ 'timezone': "Timezone('UTC')",
+ 'max_active_runs': 16,
+ 'pickle_id': None,
+ "end_date": None,
+ 'is_paused_upon_creation': None,
+ 'render_template_as_native_obj': False,
+ }
+ obj = schema.dump(dag)
+ expected.update({'last_parsed': obj['last_parsed']})
+ assert obj == expected
diff --git a/tests/conftest.py b/tests/conftest.py
index b20c0be494..b153c213d5 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -26,6 +26,8 @@ import pytest
# We should set these before loading _any_ of the rest of airflow so that the
# unit test mode config is set as early as possible.
+from itsdangerous import URLSafeSerializer
+
assert "airflow" not in sys.modules, "No airflow module can be imported before these lines"
tests_directory = os.path.dirname(os.path.realpath(__file__))
@@ -58,6 +60,28 @@ def reset_environment():
os.environ[key] = init_env[key]
+@pytest.fixture()
+def secret_key() -> str:
+ """
+ Return secret key configured.
+ :return:
+ """
+ from airflow.configuration import conf
+
+ the_key = conf.get('webserver', 'SECRET_KEY')
+ if the_key is None:
+ raise RuntimeError(
+ "The secret key SHOULD be configured as `[webserver] secret_key` in the "
+ "configuration/environment at this stage! "
+ )
+ return the_key
+
+
+@pytest.fixture()
+def url_safe_serializer(secret_key) -> URLSafeSerializer:
+ return URLSafeSerializer(secret_key)
+
+
@pytest.fixture()
def reset_db():
"""
diff --git a/tests/test_utils/remote_user_api_auth_backend.py b/tests/test_utils/remote_user_api_auth_backend.py
index 1e6a0c70ad..187f57a7fd 100644
--- a/tests/test_utils/remote_user_api_auth_backend.py
+++ b/tests/test_utils/remote_user_api_auth_backend.py
@@ -20,10 +20,12 @@ import logging
from functools import wraps
from typing import Callable, Optional, Tuple, TypeVar, Union, cast
-from flask import Response, current_app, request
+from flask import Response, request
from flask_login import login_user
from requests.auth import AuthBase
+from airflow.utils.airflow_flask_app import get_airflow_app
+
log = logging.getLogger(__name__)
CLIENT_AUTH: Optional[Union[Tuple[str, str], AuthBase]] = None
@@ -37,7 +39,7 @@ T = TypeVar("T", bound=Callable)
def _lookup_user(user_email_or_username: str):
- security_manager = current_app.appbuilder.sm
+ security_manager = get_airflow_app().appbuilder.sm
user = security_manager.find_user(email=user_email_or_username) or security_manager.find_user(
username=user_email_or_username
)
diff --git a/tests/utils/test_serve_logs.py b/tests/utils/test_serve_logs.py
index f8d3881759..ebbc663a2c 100644
--- a/tests/utils/test_serve_logs.py
+++ b/tests/utils/test_serve_logs.py
@@ -21,7 +21,6 @@ import jwt
import pytest
from freezegun import freeze_time
-from airflow.configuration import conf
from airflow.utils.jwt_signer import JWTSigner
from airflow.utils.serve_logs import create_app
from tests.test_utils.config import conf_vars
@@ -49,18 +48,18 @@ def sample_log(tmpdir):
@pytest.fixture
-def signer():
+def signer(secret_key):
return JWTSigner(
- secret_key=conf.get('webserver', 'secret_key'),
+ secret_key=secret_key,
expiration_time_in_seconds=30,
audience="task-instance-logs",
)
@pytest.fixture
-def different_audience():
+def different_audience(secret_key):
return JWTSigner(
- secret_key=conf.get('webserver', 'secret_key'),
+ secret_key=secret_key,
expiration_time_in_seconds=30,
audience="different-audience",
)
@@ -180,7 +179,7 @@ class TestServeLogs:
)
@pytest.mark.parametrize("claim_to_remove", ["iat", "exp", "nbf", "aud"])
- def test_missing_claims(self, claim_to_remove: str, client: "FlaskClient"):
+ def test_missing_claims(self, claim_to_remove: str, client: "FlaskClient", secret_key):
jwt_dict = {
"aud": "task-instance-logs",
"iat": datetime.datetime.utcnow(),
@@ -191,7 +190,7 @@ class TestServeLogs:
jwt_dict.update({"filename": 'sample.log'})
token = jwt.encode(
jwt_dict,
- conf.get('webserver', 'secret_key'),
+ secret_key,
algorithm="HS512",
)
assert (
diff --git a/tests/www/views/test_views.py b/tests/www/views/test_views.py
index 887bd4898a..fa79e145cb 100644
--- a/tests/www/views/test_views.py
+++ b/tests/www/views/test_views.py
@@ -375,52 +375,55 @@ def test_get_task_stats_from_query():
assert data == expected_data
+INVALID_DATETIME_RESPONSE = "Invalid datetime: 'invalid'"
+
+
@pytest.mark.parametrize(
"url, content",
[
(
'/rendered-templates?execution_date=invalid',
- "Invalid datetime: 'invalid'",
+ INVALID_DATETIME_RESPONSE,
),
(
'/log?execution_date=invalid',
- "Invalid datetime: 'invalid'",
+ INVALID_DATETIME_RESPONSE,
),
(
'/redirect_to_external_log?execution_date=invalid',
- "Invalid datetime: 'invalid'",
+ INVALID_DATETIME_RESPONSE,
),
(
'/task?execution_date=invalid',
- "Invalid datetime: 'invalid'",
+ INVALID_DATETIME_RESPONSE,
),
(
'dags/example_bash_operator/graph?execution_date=invalid',
- "Invalid datetime: 'invalid'",
+ INVALID_DATETIME_RESPONSE,
),
(
'dags/example_bash_operator/graph?execution_date=invalid',
- "Invalid datetime: 'invalid'",
+ INVALID_DATETIME_RESPONSE,
),
(
'dags/example_bash_operator/duration?base_date=invalid',
- "Invalid datetime: 'invalid'",
+ INVALID_DATETIME_RESPONSE,
),
(
'dags/example_bash_operator/tries?base_date=invalid',
- "Invalid datetime: 'invalid'",
+ INVALID_DATETIME_RESPONSE,
),
(
'dags/example_bash_operator/landing-times?base_date=invalid',
- "Invalid datetime: 'invalid'",
+ INVALID_DATETIME_RESPONSE,
),
(
'dags/example_bash_operator/gantt?execution_date=invalid',
- "Invalid datetime: 'invalid'",
+ INVALID_DATETIME_RESPONSE,
),
(
'extra_links?execution_date=invalid',
- "Invalid datetime: 'invalid'",
+ INVALID_DATETIME_RESPONSE,
),
],
)
diff --git a/tests/www/views/test_views_decorators.py b/tests/www/views/test_views_decorators.py
index 0e4fc12857..1de80c1214 100644
--- a/tests/www/views/test_views_decorators.py
+++ b/tests/www/views/test_views_decorators.py
@@ -213,9 +213,9 @@ def test_action_has_dag_edit_access(create_task_instance, class_type, no_instanc
else:
test_items = tis if class_type == TaskInstance else [ti.get_dagrun() for ti in tis]
test_items = test_items[0] if len(test_items) == 1 else test_items
-
- with app.create_app(testing=True).app_context():
- with mock.patch("airflow.www.views.current_app.appbuilder.sm.can_edit_dag") as mocked_can_edit:
+ application = app.create_app(testing=True)
+ with application.app_context():
+ with mock.patch.object(application.appbuilder.sm, "can_edit_dag") as mocked_can_edit:
mocked_can_edit.return_value = True
assert not isinstance(test_items, list) or len(test_items) == no_instances
assert some_view_action_which_requires_dag_edit_access(None, test_items) is True
diff --git a/tests/www/views/test_views_log.py b/tests/www/views/test_views_log.py
index 82b30f9d21..fd136351cf 100644
--- a/tests/www/views/test_views_log.py
+++ b/tests/www/views/test_views_log.py
@@ -461,7 +461,7 @@ def test_redirect_to_external_log_with_local_log_handler(log_admin_client, task_
)
response = log_admin_client.get(url)
assert 302 == response.status_code
- assert 'http://localhost/home' == response.headers['Location']
+ assert '/home' == response.headers['Location']
class _ExternalHandler(ExternalLoggingMixin):
diff --git a/tests/www/views/test_views_mount.py b/tests/www/views/test_views_mount.py
index a9fb874665..3f504e9b0f 100644
--- a/tests/www/views/test_views_mount.py
+++ b/tests/www/views/test_views_mount.py
@@ -36,7 +36,7 @@ def app():
@pytest.fixture()
def client(app):
- return werkzeug.test.Client(app, werkzeug.wrappers.BaseResponse)
+ return werkzeug.test.Client(app, werkzeug.wrappers.response.Response)
def test_mount(client):
@@ -54,4 +54,4 @@ def test_not_found(client):
def test_index(client):
resp = client.get('/test/')
assert resp.status_code == 302
- assert resp.headers['Location'] == 'http://localhost/test/home'
+ assert resp.headers['Location'] == '/test/home'