-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
🎉 Source Notion: Adds pagination to Users stream #11452
🎉 Source Notion: Adds pagination to Users stream #11452
Conversation
|
||
# When getting pages after the first pull. | ||
inputs = {"stream_slice": None, "stream_state": None, "next_page_token": {"next_cursor": "123"}} | ||
expected_params = {"start_cursor": "123", "page_size": 100} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using a dummy start_cursor value maybe use a self documenting value that will be provided from Notion such as "next_cursor": "fe2cc560-036c-44cd-90e8-294d5a74cebc"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. Updated in fda250e.
""" | ||
|
||
response_body = { | ||
"object": "list", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in fda250e.
"has_more": True, | ||
"type": "user" | ||
} | ||
url = "https://api.notion.com/v1/users?page_size=100" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a need to declare the url variable? couldn't the url be passed directly to requests_mock.get()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to requests_mock.get()
in fda250e.
stream = Users(config=MagicMock()) | ||
|
||
user_ids = set() | ||
for record in stream.read_records(sync_mode=SyncMode.full_refresh): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a need to fill the user_ids set before asserting that the set is of length 220? wouldn't the following snippet do the job? Might also save you some memory from allocating an additional data structure.
records = stream.read_records(sync_mode=SyncMode.full_refresh):
records_length = sum(1 for record in records)
assert records_length == 220
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in fda250e.
Hi @itaseskii. I've addressed your comments. Please take a look again when you get a chance and let me know if there's anything else I should do. Thanks for reviewing! |
Hey @lgomezm I have went through you changes and I have no further comments, great job! :) |
@marcosmarxm @alafanechere Hi guys. This PR has been open for a while now. Could you take a look? Thanks in advance! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @lgomezm,
Thank you for your contribution. I made minor suggestions around the tests. I'll bump the version myself as I can commit to your branch.
def test_users_request_params(patch_base_class): | ||
stream = Users(config=MagicMock()) | ||
|
||
# No next_page_token. First pull | ||
inputs = {"stream_slice": None, "stream_state": None, "next_page_token": None} | ||
expected_params = {"page_size": 100} | ||
assert stream.request_params(**inputs) == expected_params | ||
|
||
# When getting pages after the first pull. | ||
inputs = {"stream_slice": None, "stream_state": None, "next_page_token": {"next_cursor": "123"}} | ||
expected_params = {"start_cursor": "123", "page_size": 100} | ||
assert stream.request_params(**inputs) == expected_params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I suggest leverage parametrize wherever you can.
def test_users_request_params(patch_base_class): | |
stream = Users(config=MagicMock()) | |
# No next_page_token. First pull | |
inputs = {"stream_slice": None, "stream_state": None, "next_page_token": None} | |
expected_params = {"page_size": 100} | |
assert stream.request_params(**inputs) == expected_params | |
# When getting pages after the first pull. | |
inputs = {"stream_slice": None, "stream_state": None, "next_page_token": {"next_cursor": "123"}} | |
expected_params = {"start_cursor": "123", "page_size": 100} | |
assert stream.request_params(**inputs) == expected_params | |
@pytest.mark.parametrize("next_page_token, expected_params", [(None, {"page_size": 100}), ({"next_cursor": "123"}, {"start_cursor": "123", "page_size": 100})]) | |
def test_users_request_params(patch_base_class, next_page_token, expected_params): | |
stream = Users(config=MagicMock()) | |
inputs = {"stream_slice": None, "stream_state": None, "next_page_token": next_page_token} | |
assert stream.request_params(**inputs) == expected_params |
""" | ||
Test shows that Users stream uses pagination as per Notion API docs. | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I would suggest to use a function to generate your requests/responses sequence
/publish connector=connectors/source-notion auto-bump-version=false
|
/publish connector=connectors/source-notion auto-bump-version=false
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @lgomezm for this improvements. I had to update some schemas too as it looks like notion API evolved a bit.
What
Users
stream does not handle pagination. That is, it only outputs the first page of user records, which defaults to 100 (https://developers.notion.com/reference/pagination).How
request_params
stream method.Recommended reading order
streams.py
test_streams.py
🚨 User Impact 🚨
Are there any breaking changes? What is the end result perceived by the user? If yes, please merge this PR with the 🚨🚨 emoji so changelog authors can further highlight this if needed.
Pre-merge Checklist
Expand the relevant checklist and delete the others.
New Connector
Community member or Airbyter
airbyte_secret
./gradlew :airbyte-integrations:connectors:<name>:integrationTest
.README.md
bootstrap.md
. See description and examplesdocs/SUMMARY.md
docs/integrations/<source or destination>/<name>.md
including changelog. See changelog exampledocs/integrations/README.md
airbyte-integrations/builds.md
Airbyter
If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.
/test connector=connectors/<name>
command is passing/publish
command described hereUpdating a connector
Community member or Airbyter
airbyte_secret
./gradlew :airbyte-integrations:connectors:<name>:integrationTest
.README.md
bootstrap.md
. See description and examplesdocs/integrations/<source or destination>/<name>.md
including changelog. See changelog exampleAirbyter
If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.
/test connector=connectors/<name>
command is passing/publish
command described hereConnector Generator
-scaffold
in their name) have been updated with the latest scaffold by running./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates
then checking in your changesTests
Unit
Put your unit tests output here.
Integration
Put your integration tests output here.
Acceptance
Put your acceptance tests output here.