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

Database query malformed schema #226

Closed
victor-yon opened this issue Dec 30, 2023 · 1 comment
Closed

Database query malformed schema #226

victor-yon opened this issue Dec 30, 2023 · 1 comment

Comments

@victor-yon
Copy link

victor-yon commented Dec 30, 2023

Expected Behavior

Make a query with a database ID with the documented format should not return an API error.

Current Behavior

When I do this request with notion-client>=2.1 :

from config import NOTION_API_TOKEN, NOTION_DATABASE_ID
from notion_client import Client

notion = Client(auth=NOTION_API_TOKEN)
items = notion.databases.query(database_id=NOTION_DATABASE_ID).get("results")

I get this error message:

Error
Traceback (most recent call last):
  File "/.../venv/lib/python3.11/site-packages/notion_client/client.py", line 118, in _parse_response
    response.raise_for_status()
  File "/.../venv/lib/python3.11/site-packages/httpx/_models.py", line 759, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '400 Bad Request' for url 'https://api.notion.com/v1/databases/58ec7ea06a0f4750bf20d805581b5bd6/query?filter_properties=Name&filter_properties=Status&filter_properties=Motivation%20cost'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/.../tests/api/test_notion_service.py", line 19, in test_fetch_tasks_count
    counts = fetch_tasks_count()
             ^^^^^^^^^^^^^^^^^^^
  File "/.../src/api/services/notion_service.py", line 62, in fetch_tasks_count
    answer = notion.databases.query(
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../venv/lib/python3.11/site-packages/notion_client/api_endpoints.py", line 132, in query
    return self.parent.request(
           ^^^^^^^^^^^^^^^^^^^^
  File "/.../venv/lib/python3.11/site-packages/notion_client/client.py", line 194, in request
    return self._parse_response(response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../venv/lib/python3.11/site-packages/notion_client/client.py", line 126, in _parse_response
    raise APIResponseError(response, body["message"], code)
notion_client.errors.APIResponseError: The schema for the database with the following ID is malformed: xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

/usr/lib/python3.11/json/decoder.py:353: ResourceWarning: unclosed <ssl.SSLSocket fd=3, family=2, type=1, proto=6, laddr=('192.168.2.167', 47656), raddr=('104.18.41.2', 443)>
  obj, end = self.scan_once(s, idx)
ResourceWarning: Enable tracemalloc to get the object allocation traceback

The error is the same with NOTION_DATABASE_ID formatted either as: xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx or xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.

I know the NOTION_DATABASE_ID is valid because the same example is working as expected with notion-client==2.0.

Steps to Reproduce

  1. pip install --force-reinstall -v notion-client==2.1 or the current last version (2.2.1)
  2. run the example above with valid NOTION_API_TOKEN and NOTION_DATABASE_ID

Context (Environment)

  • Python 3.11.0rc1
  • notion-client>=2.1 (issue reproduced with 2.1.0 and 2.2.1, but no problem with 2.0.0)
  • OS Ubuntu 22.04.3 LTS

Possible fix

Something is wrong with 2.1 update or I missed a breaking change notice.

@victor-yon victor-yon changed the title Malformed database ID Malformed schema for database query Dec 30, 2023
@victor-yon victor-yon changed the title Malformed schema for database query Database query malformed schema Dec 30, 2023
@ramnes
Copy link
Owner

ramnes commented Jan 8, 2024

Hey,

So, there are multiple things here:

  1. the error is issued by Notion's API, not the Python client
  2. it tells you that your database query is malformed; not sure why it says "the database schema" but I'm confident that the problem isn't with the database id but with the query itself (i.e. changing the UUID format won't help)
  3. as seen in your logs, you're running this query: 'https://api.notion.com/v1/databases/58ec7ea06a0f4750bf20d805581b5bd6/query?filter_properties=Name&filter_properties=Status&filter_properties=Motivation%20cost'. I don't see how it could work correctly with 2.0.0 since filter_properties only exists since 2.1.0.

Maybe you were using filter_properties before, but it was ignored with 2.0.0, and now that it's not, it's causing an error?

Anyway, I can't replicate with what you provided so far, so I'll go ahead and close the issue, but feel free to comment and I'll reopen if needed.

@ramnes ramnes closed this as completed Jan 8, 2024
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

No branches or pull requests

2 participants