-
Notifications
You must be signed in to change notification settings - Fork 661
UN-3770 [FEAT] Opt-in pagination for list endpoints; wire Workflows page #2187
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f7e4424
UN-3770 [FEAT] Opt-in pagination for list endpoints; wire Workflows page
chandrasekharan-zipstack dab4e69
UN-3770 [FIX] Use https in pagination test stub URL
chandrasekharan-zipstack 845f2a7
UN-3770 [FIX] Address review: blank-param opt-in, stable ordering, em…
chandrasekharan-zipstack aecd00a
UN-3770 [FIX] Workflows: fix double refresh on edit and spinner on fe…
chandrasekharan-zipstack b56247d
Merge branch 'main' into feat/UN-3770-list-pagination
chandrasekharan-zipstack 1c77732
UN-3770 [FIX] Lock blank-pagination-param contract; align default pag…
chandrasekharan-zipstack 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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| """Contract tests for utils.pagination.OptionalPagination. | ||
|
|
||
| The four listing endpoints it backs (workflows, prompt studio, adapters, | ||
| connectors) are shared with dropdown/selector consumers that expect a bare | ||
| array. The opt-in behaviour below is what keeps those consumers regression-free: | ||
| no page/page_size param -> paginate_queryset returns None -> DRF serialises the | ||
| bare list; only an explicit opt-in gets the {count, next, previous, results} | ||
| envelope. | ||
|
|
||
| Deliberately DB-free and Django-settings-free (a hand-rolled request stub, no | ||
| APIRequestFactory) so it runs in the rig's unit tier. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from utils.pagination import OptionalPagination | ||
|
|
||
| QUERYSET = list(range(1, 101)) # 100 sliceable items stand in for a queryset | ||
|
|
||
|
|
||
| class _Req: | ||
| """Minimal stand-in exposing the surface DRF pagination touches.""" | ||
|
|
||
| def __init__(self, params: dict[str, str]): | ||
| self.query_params = params | ||
|
|
||
| def build_absolute_uri(self) -> str: | ||
| return "https://testserver/things/" | ||
|
|
||
|
|
||
| class TestOptionalPagination: | ||
| def test_no_params_returns_none(self): | ||
| """No opt-in -> None, so callers keep their bare-array response.""" | ||
| assert OptionalPagination().paginate_queryset(QUERYSET, _Req({})) is None | ||
|
|
||
| def test_unrelated_params_do_not_trigger_pagination(self): | ||
| req = _Req({"adapter_type": "LLM", "search": "foo"}) | ||
| assert OptionalPagination().paginate_queryset(QUERYSET, req) is None | ||
|
|
||
| def test_blank_params_do_not_trigger_pagination(self): | ||
| """Empty ?page= / ?page_size= keep the bare-array response.""" | ||
| req = _Req({"page": "", "page_size": ""}) | ||
| assert OptionalPagination().paginate_queryset(QUERYSET, req) is None | ||
|
|
||
| def test_single_blank_param_does_not_trigger_pagination(self): | ||
| for params in ({"page": ""}, {"page_size": ""}): | ||
| assert OptionalPagination().paginate_queryset(QUERYSET, _Req(params)) is None | ||
|
|
||
| def test_blank_page_with_explicit_page_size_serves_first_page(self): | ||
| """A blank ?page= alongside a real ?page_size= is page 1, not an error. | ||
|
|
||
| DRF reads the page number as `query_params.get("page") or 1`, so a blank | ||
| value falls back to the first page instead of raising NotFound. | ||
| """ | ||
| page = OptionalPagination().paginate_queryset( | ||
| QUERYSET, _Req({"page": "", "page_size": "10"}) | ||
| ) | ||
| assert page == list(range(1, 11)) | ||
|
|
||
| def test_blank_page_size_with_explicit_page_uses_default_size(self): | ||
| page = OptionalPagination().paginate_queryset( | ||
| QUERYSET, _Req({"page": "2", "page_size": ""}) | ||
| ) | ||
| assert page == list(range(51, 101)) | ||
|
|
||
| def test_page_param_opts_in(self): | ||
| paginator = OptionalPagination() | ||
| page = paginator.paginate_queryset(QUERYSET, _Req({"page": "1"})) | ||
| assert page == list(range(1, 51)) # default page_size == 50 | ||
| assert paginator.page.paginator.count == 100 | ||
|
|
||
| def test_page_size_param_alone_opts_in(self): | ||
| page = OptionalPagination().paginate_queryset(QUERYSET, _Req({"page_size": "10"})) | ||
| assert page == list(range(1, 11)) | ||
|
|
||
| def test_page_size_capped_at_max(self): | ||
| page = OptionalPagination().paginate_queryset( | ||
| QUERYSET, _Req({"page_size": "100000"}) | ||
| ) | ||
| # max_page_size (1000) caps the request; all 100 rows fit in one page | ||
| assert page == QUERYSET |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.