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

Ensure Pagination and sorting are implemented on the data endpoint #2113

Merged
merged 6 commits into from
Aug 19, 2021

Conversation

WinnyTroy
Copy link
Contributor

@WinnyTroy WinnyTroy commented Jun 29, 2021

Changes / Features implemented

  • Ensure sort filter is applied for paginated responses from the data endpoint.

Steps taken to verify this change does what is intended

  • Included tests

Side effects of implementing this change

Before submitting this PR for review, please make sure you have:

  • Included tests

Closes #2108

@WinnyTroy WinnyTroy force-pushed the 2108_sort_paginated_resonse branch 5 times, most recently from b6ae263 to 4442ae1 Compare June 29, 2021 14:19
@WinnyTroy WinnyTroy changed the title Apply sort to Data Endpoint paginated responses Apply sort when fetching specific fields in submitted data Jun 29, 2021
@WinnyTroy WinnyTroy force-pushed the 2108_sort_paginated_resonse branch 2 times, most recently from a7fcdd9 to 20303c8 Compare July 1, 2021 14:08
@WinnyTroy WinnyTroy force-pushed the 2108_sort_paginated_resonse branch from 20303c8 to ad1b77e Compare July 15, 2021 08:01
@WinnyTroy WinnyTroy force-pushed the 2108_sort_paginated_resonse branch 3 times, most recently from 62964f3 to e2ca6f7 Compare July 30, 2021 12:04
should_paginate:
# Unpack generator object to list
self.object_list = list(self.object_list)
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the pagination headers are skipped if the object_list is a generator object?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.
I assume, from the previously changes I observed a scenerio whereby data returned in JSON format was to be streamed, with no pagination.
I left the else condition to continue to handle such kinds of requests, i.e that the data returned is a generator objects and we do not want to paginate the returned response data.
A good example can be found on this test, we first return a generator object, and we dont want to paginate it, but use the limit flag instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should always paginate requests if requested no matter if we're streaming the data... It's still going to be a pain if a user requests a lot of records while streaming data is enabled

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also have a few tests that use pagination and stream data

@override_settings(STREAM_DATA=True)
def test_paginate_and_sort_streaming_data(self):

@WinnyTroy WinnyTroy force-pushed the 2108_sort_paginated_resonse branch 5 times, most recently from 6e40760 to 9421052 Compare August 5, 2021 11:28
if isinstance(self.object_list, types.GeneratorType):
# Unpack generator object to list
self.object_list = list(self.object_list)
elif should_paginate:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if it's a generator and the user asked for pagination ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will mostly result to a generator object if sort query param is passed for the JSON result.
If page and page_size headers are passed, the result will be unpacked and paginated appropriately.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still seems like if it's a generator object the pagination headers won't be included.... Seems like it's unpacked but the pagination headers are not included

@WinnyTroy WinnyTroy force-pushed the 2108_sort_paginated_resonse branch 2 times, most recently from 01f4fd2 to 5f5ec80 Compare August 5, 2021 13:43
should_paginate:
if isinstance(self.object_list, types.GeneratorType):
# Unpack generator object to list
self.object_list = list(self.object_list)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This converts the stream to a list and breaks the stream data functionality

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we paginate when fetching from the db?

@WinnyTroy WinnyTroy force-pushed the 2108_sort_paginated_resonse branch 3 times, most recently from 29c157c to ef3c04b Compare August 6, 2021 13:27
denniswambua
denniswambua previously approved these changes Aug 6, 2021
@WinnyTroy WinnyTroy changed the title Apply sort when fetching specific fields in submitted data Ensure Pagination and sorting are implemented on the data endpoint Aug 19, 2021
@DavisRayM DavisRayM merged commit 6f59432 into master Aug 19, 2021
@DavisRayM DavisRayM deleted the 2108_sort_paginated_resonse branch August 19, 2021 08:35
@DavisRayM DavisRayM mentioned this pull request Aug 26, 2021
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sorted submissions are not paginated correctly
3 participants