-
-
Notifications
You must be signed in to change notification settings - Fork 149
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
in query empty start_cursor option throws error #94
Comments
Hello @rzylius, that's quite a funny one and I've no idea what Notion is expecting from us. I'll investigate eventually, please tell me if you find anything new in the meantime! |
Removing that |
I don't think this is an issue with notion_client. In the notion API documentation it states that From https://developers.notion.com/reference/post-database-query
It seems that |
The error thrown "APIResponseError: body failed validation: body.start_cursor should be a string or |
There is no In Python, we have the concept of an optional value, where something can either be a value or |
I see two possible fixes here:
I'm not sure which one of these is the best solution... Perhaps others have an opinion. |
@nicobako , option 1 is clearly a workaround, as then you need to differentiate if this is a first run of the query or the next page. Can you elaborate on option 2? |
In the meantime, I would do: next_cursor = None
...
query = {"database_id": DB_GMB_ID}
if next_cursor:
query["start_cursor"] = next_cursor
results = notion.databases.query(**query)
... |
@rzylius , Option 2 is about changing the behaviour of For example, the endpoint |
@ramnes , would a good solution to this problem be to change the implementation of def pick(base: Dict[Any, Any], *keys: str,) -> Dict[Any, Any]:
"""Return a dict composed of key value pairs for keys passed as args."""
return {key: base[key] for key in keys if key in base and base[key] is not None} Here's an example of its usage: >>> base = {"start_cursor":None}
>>> pick(base, "start_cursor")
{}
>>> base = {"start_cursor": "start"}
>>> pick(base, "start_cursor")
{'start_cursor': 'start'} Not sure if this would always work with the Notion API. This assumes that if a value in O maybe you have an idea for a better solution. |
I stumbled on this issue today as well, it is so annoying when fetching a whole database: results = []
query = notion.databases.query(database_id=database_id, page_size=page_size)
results.extend(query['results'])
while query['next_cursor']:
query = notion.databases.query(database_id=database_id, start_cursor=query['next_cursor'], page_size=page_size)
results.extend(query['results']) Instead of something a tad more elegant, such as: results = []
query = {'next_cursor': None}
while query['next_cursor'] or query['next_cursor'] is None:
query = notion.databases.query(database_id=database_id, start_cursor=query['next_cursor'], page_size=page_size)
results.extend(query['results'])
or results = []
query = {}
while not query or query['next_cursor']:
query = notion.databases.query(database_id=database_id, start_cursor=query.get('next_cursor', None), page_size=page_size) # doesn't work because the api error when None is passed
results.extend(query['results'])
or results = []
query = {'next_cursor': 'undefined'}
while query['next_cursor']:
query = notion.databases.query(database_id=database_id, start_cursor=query['next_cursor'], page_size=page_size) # doesn't work because the api error when None is passed
results.extend(query['results'])
Not sure how to code that elegantly now I think it is needed to remove the argument |
Should be fixed now. :) |
Maybe it would be nice to have a new release ? So it is possible to have the right version of notion-sdk-py as requirement for tools that need this change ? :) |
Really good point @thomashirtz , In the meanwhile, you can pip install directly from GitHub. Here is a link to the pip documentation on vcs support: https://pip.pypa.io/en/stable/topics/vcs-support/ Here's another blog post which might be easier to read and extract useful information: https://adamj.eu/tech/2019/03/11/pip-install-from-a-git-repository/ |
I just released 0.9.0. Thanks! |
how I can write this in javascript? I stuck on start_cursor |
hi,
I try to make a query:
I receive the error:
"" produces the same result.
What value should be used to satisfy undefined start_cursor?
The text was updated successfully, but these errors were encountered: