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

BadRequest Error on Simple Query to NotionDB Database Using notion_db_secret and database_id, due to passing empty dict in json for filter by default #18009

Closed
4 tasks done
adorabledev opened this issue Feb 23, 2024 · 5 comments · Fixed by #19075
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: doc loader Related to document loader module (not documentation)

Comments

@adorabledev
Copy link

adorabledev commented Feb 23, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.

Example Code

from getpass import getpass

NOTION_TOKEN = getpass()
DATABASE_ID = getpass()

········
········

from langchain_community.document_loaders import NotionDBLoader

loader = NotionDBLoader(
    integration_token=NOTION_TOKEN,
    database_id=DATABASE_ID,
    request_timeout_sec=30,  # optional, defaults to 10
)

docs = loader.load()

print(docs)

Error Message and Stack Trace (if applicable)

b'{"object":"error","status":400,"code":"validation_error","message":"body failed validation. Fix one:\nbody.filter.or should be defined, instead was undefined.\nbody.filter.and should be defined, instead was undefined.\nbody.filter.title should be defined, instead was undefined.\nbody.filter.rich_text should be defined, instead was undefined.\nbody.filter.number should be defined, instead was undefined.\nbody.filter.checkbox should be defined, instead was undefined.\nbody.filter.select should be defined, instead was undefined.\nbody.filter.multi_select should be defined, instead was undefined.\nbody.filter.status should be defined, instead was undefined.\nbody.filter.date should be defined, instead was undefined.\nbody.filter.people should be defined, instead was undefined.\nbody.filter.files should be defined, instead was undefined.\nbody.filter.url should be defined, instead was undefined.\nbody.filter.email should be defined, instead was undefined.\nbody.filter.phone_number should be defined, instead was undefined.\nbody.filter.relation should be defined, instead was undefined.\nbody.filter.created_by should be defined, instead was undefined.\nbody.filter.created_time should be defined, instead was undefined.\nbody.filter.last_edited_by should be defined, instead was undefined.\nbody.filter.last_edited_time should be defined, instead was undefined.\nbody.filter.formula should be defined, instead was undefined.\nbody.filter.unique_id should be defined, instead was undefined.\nbody.filter.rollup should be defined, instead was undefined.","request_id":"a251ecce-5757-44bf-a5f1-c4d7582d72dd"}'

Description

getting 400, Bad Request

System Info

langchain==0.1.9
langchain-community==0.0.22
langchain-core==0.1.26

@dosubot dosubot bot added Ɑ: doc loader Related to document loader module (not documentation) 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Feb 23, 2024
@adorabledev adorabledev changed the title NotionDB Database now require 'Notion-Version' as one the Header NotionDB Database is getting bad request with simple query with notion_db_secret and database_id Feb 23, 2024
@adorabledev adorabledev changed the title NotionDB Database is getting bad request with simple query with notion_db_secret and database_id BadRequest Error on Simple Query to NotionDB Database Using Notion_db_secret and Database_ID Feb 23, 2024
@adorabledev adorabledev changed the title BadRequest Error on Simple Query to NotionDB Database Using Notion_db_secret and Database_ID BadRequest Error on Simple Query to NotionDB Database Using notion_db_secret and database_id Feb 23, 2024
@adorabledev
Copy link
Author

https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/document_loaders/notiondb.py#L214
looks like passing filter = {} is causing this issue @lyndseyjw

causing this

loader = NotionDBLoader(
    integration_token=NOTION_TOKEN,
    database_id=DATABASE_ID,
    request_timeout_sec=30,  # optional, defaults to 10
)

to fail.

notion database API supports post without filter e.g. below works.

curl --location --request POST 'https://api.notion.com/v1/databases/<database_id>/query' \
  -H 'Authorization: Bearer '"<notion_db_secret>"'' \
  -H 'Content-Type": '"application/json"'' \
  -H 'Notion-Version: 2022-06-28'

@adorabledev adorabledev changed the title BadRequest Error on Simple Query to NotionDB Database Using notion_db_secret and database_id BadRequest Error on Simple Query to NotionDB Database Using notion_db_secret and database_id, due to passing empty filter dict in the header by default Feb 23, 2024
@adorabledev adorabledev changed the title BadRequest Error on Simple Query to NotionDB Database Using notion_db_secret and database_id, due to passing empty filter dict in the header by default BadRequest Error on Simple Query to NotionDB Database Using notion_db_secret and database_id, due to passing empty dict in json for filter by default Feb 23, 2024
@adorabledev
Copy link
Author

adorabledev commented Feb 23, 2024

Created this PR to fix it.

@gagip
Copy link

gagip commented Mar 2, 2024

I am also experiencing the same issue as described above. The behavior does not work as expected for me either.

@Carr1005
Copy link

Carr1005 commented Mar 4, 2024

Same here:

requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.notion.com/v1/databases/{database-id}/query

@rivamarco
Copy link

Exactly the same issue here even with latest version

gunnzolder added a commit to gunnzolder/langchain that referenced this issue Mar 14, 2024
Modified _request method in langchain/libs/community/langchain_community/document_loaders/notiondb.py to conditionally include the 'filter' key in the JSON payload only if the filter_object is provided and not empty.

Related GitHub Issue: langchain-ai#18009
eyurtsev pushed a commit that referenced this issue Mar 14, 2024
…g filter parameter (#19075)

- **Description:** This change fixes a bug where attempts to load data
from Notion using the NotionDBLoader resulted in a 400 Bad Request
error. The issue was traced to the unconditional addition of an empty
'filter' object in the request payload, which Notion's API does not
accept. The modification ensures that the 'filter' object is only
included in the payload when it is explicitly provided and not empty,
thus preventing the 400 error from occurring.
- **Issue:** Fixes
[#18009](#18009)
- **Dependencies:** None
- **Twitter handle:** @gunnzolder

Co-authored-by: Anton Parkhomenko <anton@merge.rocks>
gkorland pushed a commit to FalkorDB/langchain that referenced this issue Mar 30, 2024
…g filter parameter (langchain-ai#19075)

- **Description:** This change fixes a bug where attempts to load data
from Notion using the NotionDBLoader resulted in a 400 Bad Request
error. The issue was traced to the unconditional addition of an empty
'filter' object in the request payload, which Notion's API does not
accept. The modification ensures that the 'filter' object is only
included in the payload when it is explicitly provided and not empty,
thus preventing the 400 error from occurring.
- **Issue:** Fixes
[langchain-ai#18009](langchain-ai#18009)
- **Dependencies:** None
- **Twitter handle:** @gunnzolder

Co-authored-by: Anton Parkhomenko <anton@merge.rocks>
hinthornw pushed a commit that referenced this issue Apr 26, 2024
…g filter parameter (#19075)

- **Description:** This change fixes a bug where attempts to load data
from Notion using the NotionDBLoader resulted in a 400 Bad Request
error. The issue was traced to the unconditional addition of an empty
'filter' object in the request payload, which Notion's API does not
accept. The modification ensures that the 'filter' object is only
included in the payload when it is explicitly provided and not empty,
thus preventing the 400 error from occurring.
- **Issue:** Fixes
[#18009](#18009)
- **Dependencies:** None
- **Twitter handle:** @gunnzolder

Co-authored-by: Anton Parkhomenko <anton@merge.rocks>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: doc loader Related to document loader module (not documentation)
Projects
None yet
4 participants