Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test fixing bad PROD image preparation in CI #39011

Closed
wants to merge 105 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
9db254d
Update methods to use Connexion v3, Ginucorn command and encoding
Nov 23, 2023
e9733a4
Fix static checks
Dec 21, 2023
ac04dac
Update setup.cfg and encoding
MaksYermak Dec 29, 2023
4274b61
Update migrations files for
MaksYermak Jan 5, 2024
3a981c1
Update configuration for tests
MaksYermak Jan 9, 2024
368a19b
Fix problem with static checks
MaksYermak Jan 9, 2024
ea90662
fix: add missing import which was removed while rebasing, add connexi…
sudiptob2 Feb 22, 2024
b77a639
fix: fix static check.
sudiptob2 Feb 23, 2024
b1016ff
changed set with get
Satoshi-Sh Feb 24, 2024
e72aeba
Refactored the code since the functions return None. Replaced 'get' w…
Satoshi-Sh Feb 24, 2024
8788688
feat: implement brefore_request to handle CSRF exemption logic.
sudiptob2 Feb 25, 2024
464bec8
test: adapt broken unit test due to connexion_app
sudiptob2 Feb 26, 2024
f5fcfed
handle swagger ui installation.
Satoshi-Sh Mar 1, 2024
4b0e3e4
Update methods to use Connexion v3, Ginucorn command and encoding
Nov 23, 2023
9e77141
Adapt unittest with environ override.
Satoshi-Sh Mar 2, 2024
8fec363
fix: fixing test_auth of connexion api.
sudiptob2 Mar 8, 2024
dbf9d18
fix: fix react www test
sudiptob2 Mar 8, 2024
498c87c
fix: adapt few test of www module.
sudiptob2 Mar 9, 2024
2763ee9
Add asset compilation when testing openapi client
potiuk Mar 18, 2024
7b22759
Add Pytest fixture to create directory that starlette needs
potiuk Mar 18, 2024
79b5328
fix: fix failing static check.
sudiptob2 Mar 18, 2024
6ae852f
Fixed StaleDataError by adding session.refresh(user)
Satoshi-Sh Mar 19, 2024
b8884df
Added '/auth/fab/v1' to the base_paths to avoid coroutine not callabl…
Satoshi-Sh Mar 19, 2024
84251a7
Modified assert 'title' and 'type' accodringly.
Satoshi-Sh Mar 19, 2024
f7501a8
fix: test_should_respond_200_with_anonymous_user fixed.
sudiptob2 Mar 20, 2024
3640aa9
fix: unit tests of experimental/test_dag_runs_endpoint.py.
sudiptob2 Mar 20, 2024
fd9ec2b
fix: adapt unit test to check for redirection.
sudiptob2 Mar 21, 2024
18c2320
fix: Added 'init_jinja_globals' to minimal app. Updated client_with_l…
Satoshi-Sh Mar 21, 2024
32a94c9
fix: adapt unit test in www/test_views
sudiptob2 Mar 21, 2024
f976e6e
fix: adapt unit test with connexion v3.
sudiptob2 Mar 22, 2024
434df72
fix: adapt unit test with connexion v3
sudiptob2 Mar 22, 2024
b6db123
fix: move connexion v3 dependency to hatch_build
sudiptob2 Mar 25, 2024
ff57ae0
fix: adapt test view dataset.
sudiptob2 Mar 25, 2024
eff5ec6
fix: adapt redirection tests with starlette tet client.
sudiptob2 Mar 27, 2024
d102883
fix: adapt test units with connextion v3 test client.
sudiptob2 Mar 27, 2024
c0b0910
fix:refactor the code for testing
Satoshi-Sh Mar 25, 2024
319647c
Created two app with differnt middleware settings
Satoshi-Sh Mar 25, 2024
88db38a
fix: adapt test units with connextion v3 test client.
sudiptob2 Mar 28, 2024
0c65143
fix: adapt test units with connextion v3 test client.
sudiptob2 Mar 28, 2024
4f176f5
fix: adapt test units with connextion v3 test client.
sudiptob2 Mar 28, 2024
32b2054
fix: adapt test units with connextion v3 test client.
sudiptob2 Mar 28, 2024
e83370b
fix: does not green the test but fix the attribute error.
sudiptob2 Mar 28, 2024
0ce9570
fix: adapt test units with connextion v3 test client.
sudiptob2 Mar 29, 2024
7b1cbb1
fix: adapt test units with connextion v3 test client.
sudiptob2 Mar 29, 2024
eb680d8
fix: adapt test units with connextion v3 test client.
sudiptob2 Mar 29, 2024
b2b5a92
fix: adapt test units with connextion v3 test client.
sudiptob2 Apr 3, 2024
e6c8145
fix: adapt test units with connextion v3 test client.
sudiptob2 Apr 3, 2024
18c4ac2
fixed test_dag_endpoint.py
Satoshi-Sh Apr 4, 2024
cace53a
fix:test_dag_run_endpoint.py
Satoshi-Sh Apr 5, 2024
e3c4139
Fixed test_dag_source_endpoint.py
Satoshi-Sh Apr 5, 2024
b9d80e4
Put back validate_responses=True.
Satoshi-Sh Apr 7, 2024
3542cba
Fix session handling in test_session_inaccessible_after_logout
potiuk Apr 9, 2024
653a143
Add "flask_client_with_login" for tests that neeed flask client
potiuk Apr 10, 2024
0e72de7
Fix error handling for new connection 3 approach
potiuk Apr 9, 2024
a44ce2c
Fix wrong response is tests_view_cluster_activity
potiuk Apr 10, 2024
f8658a5
Fix partially test_extra_links
potiuk Apr 10, 2024
5ec0608
Fix error handling for api connexion test
potiuk Apr 10, 2024
e5555cd
Switch to non-deprecated auth manager
potiuk Apr 10, 2024
23fe4f7
Partially fix test_views_log.py
potiuk Apr 10, 2024
e79b455
Fix views_custom_user_views tests
potiuk Apr 10, 2024
b82d56c
Fix test views dataaset
potiuk Apr 10, 2024
e3d49db
Fix test_views_grid
potiuk Apr 10, 2024
2297c6e
Reverted errro messages
Satoshi-Sh Apr 10, 2024
430d04d
fix: assert response text properly.
sudiptob2 Apr 10, 2024
fbc8f4d
Fixed test_event_log_endpoint.py
Satoshi-Sh Apr 10, 2024
d1be468
fix: adapt test in test_views_home.py
sudiptob2 Apr 10, 2024
7b06825
fix: adapt test in test_views_log.py
sudiptob2 Apr 10, 2024
5d7ecba
Fixed test_health_endpoint.py
Satoshi-Sh Apr 10, 2024
c84fed5
fix test_extra_link_endpoint.py
Satoshi-Sh Apr 10, 2024
d6095ad
Fixed test_pool_endpoint.py except for one case
Satoshi-Sh Apr 11, 2024
e470d46
Reverted error message
Satoshi-Sh Apr 11, 2024
1bb53c8
Replaced json with json().
Satoshi-Sh Apr 11, 2024
bb5fd68
Fixed test_version_endpoint.py and test_xcom_endpoint.py
Satoshi-Sh Apr 11, 2024
6692b5b
Revereted error message and added session.close()
Satoshi-Sh Apr 11, 2024
5baeef9
Fixed test_rpc_api_endpoint.py
Satoshi-Sh Apr 11, 2024
7e88355
fix: adapt test_view_tasks.
sudiptob2 Apr 11, 2024
14fe94d
fix: adapt test_view_tasks.
sudiptob2 Apr 11, 2024
b9f65fb
Fix most test_task_instance_endpoint tests
potiuk Apr 12, 2024
54fb1b2
Fix parameter validation
potiuk Apr 12, 2024
8aa2bb1
Fixed response validator errors
Satoshi-Sh Apr 12, 2024
9147dc6
Fixed test_variable_endpoint.py
Satoshi-Sh Apr 12, 2024
0e28729
Fix most session problems
potiuk Apr 12, 2024
8f99a14
Fix all FAB provider tests
potiuk Apr 12, 2024
9683da4
Fix missing session.close() / commit() in mapped instance endpoint
potiuk Apr 12, 2024
8f5df93
Fix most test_log_enpoint tests
potiuk Apr 12, 2024
a16ff07
Fixed test_rpc_api_endpoint.py
Satoshi-Sh Apr 12, 2024
37c4d14
Fixed test_dag_run_schema.py
Satoshi-Sh Apr 12, 2024
8002f3b
Fixed two failing tests
Satoshi-Sh Apr 12, 2024
84dc0fa
fix: adapt url encoded assertions.
sudiptob2 Apr 12, 2024
ec0d59e
fix: adapt test views variables.
sudiptob2 Apr 12, 2024
630d086
Fix integration test
potiuk Apr 12, 2024
79a7757
Fix static checks
potiuk Apr 12, 2024
c507cfe
fix: used admin_flask_client to fix the filing tests.
sudiptob2 Apr 12, 2024
1af7332
fix: adapt test_views_task_norun.py
sudiptob2 Apr 12, 2024
8421011
fix: adapt test_views_rendered.py
sudiptob2 Apr 12, 2024
16cd79e
fix: adapt test_views_robots.py
sudiptob2 Apr 12, 2024
3bf4c0b
Fix test_views_rate_limit.py
Satoshi-Sh Apr 13, 2024
bce1322
Fix test_views_paused
potiuk Apr 14, 2024
a15678c
Better fix for rate_view_one
potiuk Apr 14, 2024
d40ae4b
Fix test_views_dagrun, test_views_tasks and test_views_log
potiuk Apr 14, 2024
34c0c70
Fix more integration tests
potiuk Apr 12, 2024
8a2c6ed
Fix test_views_dagrun
potiuk Apr 14, 2024
35225e2
Fix test_process_form_invalid_extra_removed
potiuk Apr 14, 2024
ae320ca
For testing - remove the lingk to swagger /api/v1
potiuk Apr 14, 2024
3dbbe4a
Fix PROD image package installation in CI
potiuk Apr 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/basic-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ jobs:
env:
HATCH_ENV: "test"
working-directory: ./clients/python
- name: Compile www assets
run: breeze compile-www-assets
- name: "Install Airflow in editable mode with fab for webserver tests"
run: pip install -e ".[fab]"
- name: "Install Python client"
Expand Down
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,10 @@ function install_airflow_and_providers_from_docker_context_files(){
${ADDITIONAL_PIP_INSTALL_FLAGS} --constraint "${local_constraints_file}" \
"${install_airflow_package[@]}" "${installing_providers_packages[@]}"
set +x
echo
echo "${COLOR_BLUE}Copying ${local_constraints_file} to ${HOME}/constraints.txt${COLOR_RESET}"
echo
cp "${local_constraints_file}" "${HOME}/constraints.txt"
else
echo
echo "${COLOR_BLUE}Installing docker-context-files packages with constraints from GitHub${COLOR_RESET}"
Expand Down
2 changes: 1 addition & 1 deletion airflow/api_connexion/endpoints/connection_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_connection(*, connection_id: str, session: Session = NEW_SESSION) -> API
@provide_session
def get_connections(
*,
limit: int,
limit: int | None = None,
offset: int = 0,
order_by: str = "id",
session: Session = NEW_SESSION,
Expand Down
2 changes: 1 addition & 1 deletion airflow/api_connexion/endpoints/dag_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def get_dag_details(
@provide_session
def get_dags(
*,
limit: int,
limit: int | None = None,
offset: int = 0,
tags: Collection[str] | None = None,
dag_id_pattern: str | None = None,
Expand Down
2 changes: 1 addition & 1 deletion airflow/api_connexion/endpoints/dag_warning_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
@provide_session
def get_dag_warnings(
*,
limit: int,
limit: int | None = None,
dag_id: str | None = None,
warning_type: str | None = None,
offset: int | None = None,
Expand Down
6 changes: 3 additions & 3 deletions airflow/api_connexion/endpoints/dataset_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def get_dataset(*, uri: str, session: Session = NEW_SESSION) -> APIResponse:
@provide_session
def get_datasets(
*,
limit: int,
limit: int | None = None,
offset: int = 0,
uri_pattern: str | None = None,
dag_ids: str | None = None,
Expand Down Expand Up @@ -113,11 +113,11 @@ def get_datasets(


@security.requires_access_dataset("GET")
@provide_session
@format_parameters({"limit": check_limit})
@provide_session
def get_dataset_events(
*,
limit: int,
limit: int | None = None,
offset: int = 0,
order_by: str = "timestamp",
dataset_id: int | None = None,
Expand Down
2 changes: 1 addition & 1 deletion airflow/api_connexion/endpoints/event_log_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_event_logs(
included_events: str | None = None,
before: str | None = None,
after: str | None = None,
limit: int,
limit: int | None = None,
offset: int | None = None,
order_by: str = "event_log_id",
session: Session = NEW_SESSION,
Expand Down
2 changes: 1 addition & 1 deletion airflow/api_connexion/endpoints/import_error_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_import_error(*, import_error_id: int, session: Session = NEW_SESSION) ->
@provide_session
def get_import_errors(
*,
limit: int,
limit: int | None = None,
offset: int | None = None,
order_by: str = "import_error_id",
session: Session = NEW_SESSION,
Expand Down
5 changes: 4 additions & 1 deletion airflow/api_connexion/endpoints/log_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ def get_log(
logs = logs[0] if task_try_number is not None else logs
# 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))
return Response(
logs_schema.dumps(LogResponseObject(continuation_token=token, content=logs)),
headers={"Content-Type": "application/json"},
)
# text/plain. Stream
logs = task_log_reader.read_log_stream(ti, task_try_number, metadata)

Expand Down
2 changes: 1 addition & 1 deletion airflow/api_connexion/endpoints/pool_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_pool(*, pool_name: str, session: Session = NEW_SESSION) -> APIResponse:
@provide_session
def get_pools(
*,
limit: int,
limit: int | None = None,
order_by: str = "id",
offset: int | None = None,
session: Session = NEW_SESSION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def _apply_range_filter(query: Select, key: ClauseElement, value_range: tuple[T,
@provide_session
def get_task_instances(
*,
limit: int,
limit: int | None = None,
dag_id: str | None = None,
dag_run_id: str | None = None,
execution_date_gte: str | None = None,
Expand Down
55 changes: 23 additions & 32 deletions airflow/api_connexion/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
from http import HTTPStatus
from typing import TYPE_CHECKING, Any

import werkzeug
from connexion import FlaskApi, ProblemException, problem
from connexion import ProblemException, problem

from airflow.utils.docs import get_docs_url

if TYPE_CHECKING:
import flask
from connexion.lifecycle import ConnexionRequest, ConnexionResponse

doc_link = get_docs_url("stable-rest-api-ref.html")

Expand All @@ -40,37 +39,29 @@
}


def common_error_handler(exception: BaseException) -> flask.Response:
def problem_error_handler(_request: ConnexionRequest, exception: ProblemException) -> ConnexionResponse:
"""Use to capture connexion exceptions and add link to the type field."""
if isinstance(exception, ProblemException):
link = EXCEPTIONS_LINK_MAP.get(exception.status)
if link:
response = problem(
status=exception.status,
title=exception.title,
detail=exception.detail,
type=link,
instance=exception.instance,
headers=exception.headers,
ext=exception.ext,
)
else:
response = problem(
status=exception.status,
title=exception.title,
detail=exception.detail,
type=exception.type,
instance=exception.instance,
headers=exception.headers,
ext=exception.ext,
)
link = EXCEPTIONS_LINK_MAP.get(exception.status)
if link:
return problem(
status=exception.status,
title=exception.title,
detail=exception.detail,
type=link,
instance=exception.instance,
headers=exception.headers,
ext=exception.ext,
)
else:
if not isinstance(exception, werkzeug.exceptions.HTTPException):
exception = werkzeug.exceptions.InternalServerError()

response = problem(title=exception.name, detail=exception.description, status=exception.code)

return FlaskApi.get_response(response)
return problem(
status=exception.status,
title=exception.title,
detail=exception.detail,
type=exception.type,
instance=exception.instance,
headers=exception.headers,
ext=exception.ext,
)


class NotFound(ProblemException):
Expand Down
61 changes: 35 additions & 26 deletions airflow/api_connexion/openapi/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,10 @@ paths:
responses:
"204":
description: Success.
content:
text/html:
schema:
type: string
"400":
$ref: "#/components/responses/BadRequest"
"401":
Expand Down Expand Up @@ -1743,6 +1747,10 @@ paths:
responses:
"204":
description: Success.
content:
text/html:
schema:
type: string
"400":
$ref: "#/components/responses/BadRequest"
"401":
Expand Down Expand Up @@ -1885,8 +1893,8 @@ paths:
response = self.client.get(
request_url,
query_string={"token": token},
headers={"Accept": "text/plain"},
environ_overrides={"REMOTE_USER": "test"},
headers={"Accept": "text/plain","REMOTE_USER": "test"},

)
continuation_token = response.json["continuation_token"]
metadata = URLSafeSerializer(key).loads(continuation_token)
Expand Down Expand Up @@ -2020,7 +2028,7 @@ paths:
properties:
content:
type: string
plain/text:
text/plain:
schema:
type: string

Expand Down Expand Up @@ -2106,29 +2114,6 @@ paths:
"403":
$ref: "#/components/responses/PermissionDenied"

/datasets/{uri}:
parameters:
- $ref: "#/components/parameters/DatasetURI"
get:
summary: Get a dataset
description: Get a dataset by uri.
x-openapi-router-controller: airflow.api_connexion.endpoints.dataset_endpoint
operationId: get_dataset
tags: [Dataset]
responses:
"200":
description: Success.
content:
application/json:
schema:
$ref: "#/components/schemas/Dataset"
"401":
$ref: "#/components/responses/Unauthenticated"
"403":
$ref: "#/components/responses/PermissionDenied"
"404":
$ref: "#/components/responses/NotFound"

/datasets/events:
get:
summary: Get dataset events
Expand Down Expand Up @@ -2186,6 +2171,30 @@ paths:
'404':
$ref: '#/components/responses/NotFound'

/datasets/{uri}:
parameters:
- $ref: "#/components/parameters/DatasetURI"
get:
summary: Get a dataset
description: Get a dataset by uri.
x-openapi-router-controller: airflow.api_connexion.endpoints.dataset_endpoint
operationId: get_dataset
tags: [Dataset]
responses:
"200":
description: Success.
content:
application/json:
schema:
$ref: "#/components/schemas/Dataset"
"401":
$ref: "#/components/responses/Unauthenticated"
"403":
$ref: "#/components/responses/PermissionDenied"
"404":
$ref: "#/components/responses/NotFound"


/config:
get:
summary: Get current configuration
Expand Down
14 changes: 9 additions & 5 deletions airflow/api_connexion/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def validate_istimezone(value: datetime) -> None:
raise BadRequest("Invalid datetime format", detail="Naive datetime is disallowed")


def format_datetime(value: str) -> datetime:
def format_datetime(value: str | None) -> datetime | None:
"""
Format datetime objects.

Expand All @@ -50,6 +50,8 @@ def format_datetime(value: str) -> datetime:

This should only be used within connection views because it raises 400
"""
if value is None:
return None
value = value.strip()
if value[-1] != "Z":
value = value.replace(" ", "+")
Expand All @@ -59,7 +61,7 @@ def format_datetime(value: str) -> datetime:
raise BadRequest("Incorrect datetime argument", detail=str(err))


def check_limit(value: int) -> int:
def check_limit(value: int | None) -> int:
"""
Check the limit does not exceed configured value.

Expand All @@ -68,7 +70,8 @@ def check_limit(value: int) -> int:
"""
max_val = conf.getint("api", "maximum_page_limit") # user configured max page limit
fallback = conf.getint("api", "fallback_page_limit")

if value is None:
return fallback
if value > max_val:
log.warning(
"The limit param value %s passed in API exceeds the configured maximum page limit %s",
Expand Down Expand Up @@ -99,8 +102,9 @@ def format_parameters_decorator(func: T) -> T:
@wraps(func)
def wrapped_function(*args, **kwargs):
for key, formatter in params_formatters.items():
if key in kwargs:
kwargs[key] = formatter(kwargs[key])
value = formatter(kwargs.get(key))
if value:
kwargs[key] = value
return func(*args, **kwargs)

return cast(T, wrapped_function)
Expand Down
6 changes: 3 additions & 3 deletions airflow/auth/managers/base_auth_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from airflow.utils.session import NEW_SESSION, provide_session

if TYPE_CHECKING:
from flask import Blueprint
import connexion
from flask_appbuilder.menu import MenuItem
from sqlalchemy.orm import Session

Expand Down Expand Up @@ -81,8 +81,8 @@ def get_cli_commands() -> list[CLICommand]:
"""
return []

def get_api_endpoints(self) -> None | Blueprint:
"""Return API endpoint(s) definition for the auth manager."""
def set_api_endpoints(self, connexion_app: connexion.FlaskApp) -> None:
"""Set API endpoint(s) definition for the auth manager."""
return None

def get_user_name(self) -> str:
Expand Down