Skip to content

Commit 2ed3969

Browse files
Respect maximum page limit in API (#60989)
* Respect maximum page limit in API * Fix CI
1 parent 4e8274c commit 2ed3969

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

airflow-core/src/airflow/api_fastapi/common/parameters.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from airflow.api_fastapi.compat import HTTP_422_UNPROCESSABLE_CONTENT
4343
from airflow.api_fastapi.core_api.base import OrmClause
4444
from airflow.api_fastapi.core_api.security import GetUserDep
45+
from airflow.configuration import conf
4546
from airflow.models import Base
4647
from airflow.models.asset import (
4748
AssetAliasModel,
@@ -102,8 +103,8 @@ def to_orm(self, select: Select) -> Select:
102103
return select.limit(self.value)
103104

104105
@classmethod
105-
def depends(cls, limit: NonNegativeInt = 50) -> LimitFilter:
106-
return cls().set_value(limit)
106+
def depends(cls, limit: NonNegativeInt = conf.getint("api", "page_size")) -> LimitFilter:
107+
return cls().set_value(min(limit, conf.getint("api", "maximum_page_limit")))
107108

108109

109110
class OffsetFilter(BaseParam[NonNegativeInt]):

airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_task_instances.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
from tests_common.test_utils.api_fastapi import _check_task_instance_note
4848
from tests_common.test_utils.asserts import assert_queries_count
49+
from tests_common.test_utils.config import conf_vars
4950
from tests_common.test_utils.db import (
5051
clear_db_runs,
5152
clear_rendered_ti_fields,
@@ -833,8 +834,8 @@ def test_offset_limit(self, test_client, one_task_with_many_mapped_tis):
833834
({"order_by": "map_index", "limit": 100}, list(range(100))),
834835
({"order_by": "-map_index", "limit": 100}, list(range(109, 9, -1))),
835836
(
836-
{"order_by": "state", "limit": 108},
837-
list(range(5, 25)) + list(range(25, 110)) + list(range(3)),
837+
{"order_by": "state", "limit": 108}, # Maximum page limit will limit result to 100 items.
838+
list(range(5, 25)) + list(range(25, 105)),
838839
),
839840
(
840841
{"order_by": "-state", "limit": 100},
@@ -849,6 +850,8 @@ def test_offset_limit(self, test_client, one_task_with_many_mapped_tis):
849850
def test_mapped_instances_order(
850851
self, test_client, session, params, expected_map_indexes, one_task_with_many_mapped_tis
851852
):
853+
from airflow.configuration import conf
854+
852855
with assert_queries_count(4):
853856
response = test_client.get(
854857
"/dags/mapped_tis/dagRuns/run_mapped_tis/taskInstances/task_2/listMapped",
@@ -858,7 +861,7 @@ def test_mapped_instances_order(
858861
assert response.status_code == 200
859862
body = response.json()
860863
assert body["total_entries"] == 110
861-
assert len(body["task_instances"]) == params["limit"]
864+
assert len(body["task_instances"]) == min(params["limit"], conf.getint("api", "maximum_page_limit"))
862865
assert expected_map_indexes == [ti["map_index"] for ti in body["task_instances"]]
863866

864867
# Ordering of nulls values is DB specific.
@@ -870,6 +873,7 @@ def test_mapped_instances_order(
870873
({"order_by": "-rendered_map_index", "limit": 100}, [0] + list(range(11, 110)[::-1])), # Desc
871874
],
872875
)
876+
@conf_vars({("api", "maximum_page_limit"): "110"})
873877
def test_rendered_map_index_order(
874878
self, test_client, session, params, expected_map_indexes, one_task_with_many_mapped_tis
875879
):

0 commit comments

Comments
 (0)