-
Notifications
You must be signed in to change notification settings - Fork 16.6k
[v3-1-test] Respect maximum page limit in API (#60989) #61073
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
Merged
Merged
[v3-1-test] Respect maximum page limit in API (#60989) #61073
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ | |
| from airflow._shared.timezones import timezone | ||
| from airflow.api_fastapi.core_api.base import OrmClause | ||
| from airflow.api_fastapi.core_api.security import GetUserDep | ||
| from airflow.configuration import conf | ||
| from airflow.models import Base | ||
| from airflow.models.asset import ( | ||
| AssetAliasModel, | ||
|
|
@@ -99,8 +100,8 @@ def to_orm(self, select: Select) -> Select: | |
| return select.limit(self.value) | ||
|
|
||
| @classmethod | ||
| def depends(cls, limit: NonNegativeInt = 50) -> LimitFilter: | ||
| return cls().set_value(limit) | ||
| def depends(cls, limit: NonNegativeInt = conf.getint("api", "page_size")) -> LimitFilter: | ||
| return cls().set_value(min(limit, conf.getint("api", "maximum_page_limit"))) | ||
|
|
||
|
|
||
| class OffsetFilter(BaseParam[NonNegativeInt]): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ | |
|
|
||
| from tests_common.test_utils.api_fastapi import _check_task_instance_note | ||
| from tests_common.test_utils.asserts import assert_queries_count | ||
| from tests_common.test_utils.config import conf_vars | ||
| from tests_common.test_utils.db import ( | ||
| clear_db_runs, | ||
| clear_rendered_ti_fields, | ||
|
|
@@ -785,8 +786,8 @@ def test_offset_limit(self, test_client, one_task_with_many_mapped_tis): | |
| ({"order_by": "map_index", "limit": 100}, list(range(100))), | ||
| ({"order_by": "-map_index", "limit": 100}, list(range(109, 9, -1))), | ||
| ( | ||
| {"order_by": "state", "limit": 108}, | ||
| list(range(5, 25)) + list(range(25, 110)) + list(range(3)), | ||
| {"order_by": "state", "limit": 108}, # Maximum page limit will limit result to 100 items. | ||
| list(range(5, 25)) + list(range(25, 105)), | ||
| ), | ||
| ( | ||
| {"order_by": "-state", "limit": 100}, | ||
|
|
@@ -801,6 +802,8 @@ def test_offset_limit(self, test_client, one_task_with_many_mapped_tis): | |
| def test_mapped_instances_order( | ||
| self, test_client, session, params, expected_map_indexes, one_task_with_many_mapped_tis | ||
| ): | ||
| from airflow.configuration import conf | ||
|
|
||
| with assert_queries_count(4): | ||
| response = test_client.get( | ||
| "/dags/mapped_tis/dagRuns/run_mapped_tis/taskInstances/task_2/listMapped", | ||
|
|
@@ -810,7 +813,7 @@ def test_mapped_instances_order( | |
| assert response.status_code == 200 | ||
| body = response.json() | ||
| assert body["total_entries"] == 110 | ||
| assert len(body["task_instances"]) == params["limit"] | ||
| assert len(body["task_instances"]) == min(params["limit"], conf.getint("api", "maximum_page_limit")) | ||
| assert expected_map_indexes == [ti["map_index"] for ti in body["task_instances"]] | ||
|
|
||
| # Ordering of nulls values is DB specific. | ||
|
|
@@ -822,6 +825,7 @@ def test_mapped_instances_order( | |
| ({"order_by": "-rendered_map_index", "limit": 100}, [0] + list(range(11, 110)[::-1])), # Desc | ||
| ], | ||
| ) | ||
| @conf_vars({("api", "maximum_page_limit"): "110"}) | ||
| def test_rendered_map_index_order( | ||
| self, test_client, session, params, expected_map_indexes, one_task_with_many_mapped_tis | ||
| ): | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.