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

Basic pagination support for result sets. #51

Closed
wants to merge 16 commits into from
Closed

Basic pagination support for result sets. #51

wants to merge 16 commits into from

Conversation

jheddings
Copy link
Contributor

@jheddings jheddings commented Jun 1, 2021

Creates an iterator from a database query, which fetches new results as needed.

If this looks like a reasonable approach, I will look into adding support for the other endpoints.

Copy link
Contributor

@aahnik aahnik left a comment

Choose a reason for hiding this comment

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

Everything looks right! This is really helpful.

Have you run pre-commit run?

The docstrings don't comply with pydocstyle. Little modifications will fix all the warnings.

@jheddings jheddings marked this pull request as draft June 2, 2021 02:43
@jheddings
Copy link
Contributor Author

Have you run pre-commit run?

How do I run this manually?

@aahnik
Copy link
Contributor

aahnik commented Jun 2, 2021

How do I run this manually?

By running the command pre-commit run -a

For more details read the contributing guidelines page in the website.

https://ramnes.github.io/notion-sdk-py/contributing/contributing/

@jheddings jheddings marked this pull request as ready for review June 2, 2021 19:09
@jheddings
Copy link
Contributor Author

Okay, added the additional paging endpoints and fixed the pre-commit failures.

@jheddings jheddings marked this pull request as draft June 2, 2021 19:16
@jheddings
Copy link
Contributor Author

Hang on... Found a bug.

@jheddings jheddings marked this pull request as ready for review June 2, 2021 19:18
Comment on lines 73 to 78
def load_next_page(self) -> Any:
"""Must be implemented in subclasses.

Returns the next page of content or None.
"""
raise ValueError

This comment was marked as outdated.

Copy link
Contributor

@aahnik aahnik left a comment

Choose a reason for hiding this comment

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

this looks nice 🎉

@aahnik
Copy link
Contributor

aahnik commented Jun 3, 2021

Hi @jheddings, it would be great if you please add an example to use this new features.

@ramnes
Copy link
Owner

ramnes commented Jun 3, 2021

Can you find a way to make this generic? The ResultSetIterator children classes feel noisy to me, they're basically all the same. A simple way I see to achieve this would be to give the endpoint method rather than the client to the iterator constructor.

@ramnes
Copy link
Owner

ramnes commented Jun 3, 2021

And yes, as @aahnik said, this needs an example somewhere at the very least, and ideally tests. :)

@jheddings
Copy link
Contributor Author

Added examples and some documentation... I added a general form of the iterator, but personally I like having the explicit iterators for clarity in the code. It also keeps doors open in the future if there is any need to handle results differently, for example if we use this in the upcoming ORM feature. We can remove if you guys disagree.

As for testing, I'll keep looking into it. It's difficult without mocked endpoints, but I'll see what I can do.

@ramnes
Copy link
Owner

ramnes commented Jun 3, 2021

Yeah I'd prefer to keep the code as concise as possible and have only one way to do things, please. :)

@ramnes
Copy link
Owner

ramnes commented Jun 3, 2021

For the tests, I don't think you actually need to call the API nor to mock it, you can just give any function that returns what you expect to receive from an endpoint method.

@jheddings
Copy link
Contributor Author

Yeah I'd prefer to keep the code as concise as possible and have only one way to do things, please. :)

It's your world, boss ;) Removed the specific iterator classes and updated docs / examples.

For the tests, I don't think you actually need to call the API nor to mock it, you can just give any function that returns what you expect to receive from an endpoint method.

I added a basic test with a mock endpoint. I'm not sure if there is a place to submit the tests for automatic execution, but it is working locally :)

@@ -0,0 +1,26 @@
import os

Choose a reason for hiding this comment

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

Just a thought, may be you can combine all the iterators in 1 file. It feels fairly repetitive.

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 is... But the point of the examples are to provide specific, easy to read use cases. Combining all endpoints in a single file makes it harder to pick out the point of each example. I'm happy with the way it is, but of course someone is always free to make further changes.

@aahnik
Copy link
Contributor

aahnik commented Jun 8, 2021

Tests failed due to codecov upload error codecov/codecov-action#330

@jheddings
Copy link
Contributor Author

It looks like the Codecov checks are missing the actions API upload token...

@aahnik
Copy link
Contributor

aahnik commented Jun 8, 2021

codecov does not require token for public repos.

but they are recently having an issue. #54 fixes it.

@ramnes please add the codecov token in github secrets.

@codecov-commenter
Copy link

codecov-commenter commented Jun 8, 2021

Codecov Report

Merging #51 (9b61dca) into main (612dea4) will decrease coverage by 11.15%.
The diff coverage is 95.08%.

❗ Current head 9b61dca differs from pull request most recent head 558dff0. Consider uploading reports for the commit 558dff0 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##             main      #51       +/-   ##
===========================================
- Coverage   90.10%   78.94%   -11.16%     
===========================================
  Files           7        7               
  Lines         192      266       +74     
===========================================
+ Hits          173      210       +37     
- Misses         19       56       +37     
Impacted Files Coverage Δ
notion_client/helpers.py 94.80% <95.08%> (+1.05%) ⬆️
notion_client/client.py 68.35% <0.00%> (-29.12%) ⬇️
notion_client/errors.py 73.21% <0.00%> (-19.47%) ⬇️
notion_client/typing.py 100.00% <0.00%> (ø)
notion_client/api_endpoints.py 69.23% <0.00%> (+0.93%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 612dea4...558dff0. Read the comment docs.

@ramnes
Copy link
Owner

ramnes commented Jun 8, 2021

I just ran checks again and it passed. Looks like Codecov guys fixed it. :)

@jheddings
Copy link
Contributor Author

Any concerns merging this PR? It's starting to drift from main, so I've pulled the latest into the branch.

@ramnes
Copy link
Owner

ramnes commented Jul 29, 2021

Hey, sorry for the silence; I'm not sure about the API and it's on my to-do list to wrap my head around this but I haven't managed to do it yet.

@jheddings
Copy link
Contributor Author

Hey, sorry for the silence; I'm not sure about the API and it's on my to-do list to wrap my head around this but I haven't managed to do it yet.

No worries... I have created a "higher level" module for the API to avoid cluttering up the core SDK. Check out notional if you are interested.

@ramnes
Copy link
Owner

ramnes commented Aug 14, 2021

You put a great effort there! Let's close this in favor of notional... for now. :P

@ramnes ramnes closed this Aug 14, 2021
@patrickwalton
Copy link

patrickwalton commented Dec 29, 2022

It'd be great to see this reopened and merged.

@ramnes
Copy link
Owner

ramnes commented Dec 29, 2022

@patrickwalton Basic pagination support has been implemented a few months ago, and that's shown in the README: https://github.com/ramnes/notion-sdk-py#utility-functions

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.

None yet

6 participants