fix(api): narrow WaterCrawl JSON responses for type checking#35113
Open
claytonlin1110 wants to merge 2 commits intolanggenius:mainfrom
Open
fix(api): narrow WaterCrawl JSON responses for type checking#35113claytonlin1110 wants to merge 2 commits intolanggenius:mainfrom
claytonlin1110 wants to merge 2 commits intolanggenius:mainfrom
Conversation
f83ba1f to
55c3e1c
Compare
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-14 03:01:09.428394502 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-14 03:00:59.255399164 +0000
@@ -101,7 +101,7 @@
ERROR Argument `dict[str, bytes | str]` is not assignable to parameter `headers` with type `Headers | Mapping[bytes, bytes] | Mapping[str, str] | Sequence[tuple[bytes, bytes]] | Sequence[tuple[str, str]] | None` in function `httpx._api.request` [bad-argument-type]
--> core/rag/extractor/notion_extractor.py:371:21
ERROR Argument `Unknown | None` is not assignable to parameter `result_object` with type `dict[str, Any]` in function `WaterCrawlProvider._structure_data` [bad-argument-type]
- --> core/rag/extractor/watercrawl/provider.py:108:37
+ --> core/rag/extractor/watercrawl/provider.py:120:37
ERROR Object of class `BaseOxmlElement` has no attribute `body` [missing-attribute]
--> core/rag/extractor/word_extractor.py:426:24
ERROR Object of class `Document` has no attribute `score` [missing-attribute]
|
Author
|
@asukaminato0721 Would you please review? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #32791
Problem
get_crawl_request (and related client helpers) are inferred from process_response as dict | bytes | list | None | Generator, so subscripting and .get on the result triggered [bad-index] / unsupported subscript errors (see langgenius/dify#32791).
Solution
Introduce _require_json_dict(value, operation=...) that validates isinstance(value, dict) and returns dict[str, Any], otherwise raises WaterCrawlError. Use it for create_crawl_request, get_crawl_request, and get_crawl_request_results in WaterCrawlProvider.
Docs
Add api/agent-notes/core/rag/extractor/watercrawl/provider.py.md describing the invariant.
Checklist
make lint && make type-check(backend) andcd web && pnpm exec vp staged(frontend) to appease the lint gods