Repository navigation
Conversation
…trict pyrefly The webhook node tests dropped two assignments to a runtime-state field the runtime does not define, and read the default config through a narrowing helper instead of indexing an object. The extract processor tests build the extraction input the way the extractor itself does, and type the captured upload fields.
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-11-23 19:13:55.621457603 +0000
+++ /tmp/pyrefly_pr.txt 2026-11-23 19:13:28.948250406 +0000
@@ -3878,10 +3878,6 @@
--> tests/unit_tests/core/rag/datasource/test_retrieval_service.py:148:18
ERROR Argument `list[FromClause]` is not assignable to parameter `tables` with type `Sequence[Table] | None` in function `sqlalchemy.sql.schema.MetaData.create_all` [bad-argument-type]
--> tests/unit_tests/core/rag/extractor/test_excel_extractor.py:17:56
-ERROR Argument `UploadFile` is not assignable to parameter `upload_file` with type `Mapping[str, Any] | UploadFileExtractionInput | None` in function `core.rag.extractor.entity.extract_setting.ExtractSetting.__init__` [bad-argument-type]
- --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:249:25
-ERROR Argument `object | None` is not assignable to parameter `session` with type `Session | None` in function `core.rag.extractor.extract_processor.ExtractProcessor.extract` [bad-argument-type]
- --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:252:85
ERROR Method `run` inherited from class `BaseRerankRunner` has no implementation and cannot be accessed via `super()` [abstract-method-call]
--> tests/unit_tests/core/rag/rerank/test_rerank_model.py:425:16
ERROR Object of class `FunctionType` has no attribute `return_value` [missing-attribute]
@@ -4733,30 +4729,6 @@
--> tests/unit_tests/core/workflow/nodes/knowledge_retrieval/test_knowledge_retrieval_node.py:617:16
ERROR `None` is not subscriptable [unsupported-operation]
--> tests/unit_tests/core/workflow/nodes/knowledge_retrieval/test_knowledge_retrieval_node.py:618:16
-ERROR Object of class `RuntimeState` has no attribute `app_config` [missing-attribute]
- --> tests/unit_tests/core/workflow/nodes/trigger_webhook/test_node.py:66:5
-ERROR Object of class `RuntimeState` has no attribute `app_config` [missing-attribute]
- --> tests/unit_tests/core/workflow/nodes/trigger_webhook/test_node.py:67:5
-ERROR Object of class `RuntimeState` has no attribute `app_config` [missing-attribute]
- --> tests/unit_tests/core/workflow/nodes/trigger_webhook/test_node.py:485:5
-ERROR Cannot index into `object` [bad-index]
- --> tests/unit_tests/core/workflow/nodes/trigger_webhook/test_node.py:503:12
-ERROR Cannot index into `object` [bad-index]
- --> tests/unit_tests/core/workflow/nodes/trigger_webhook/test_node.py:504:12
-ERROR Cannot index into `object` [bad-index]
- --> tests/unit_tests/core/workflow/nodes/trigger_webhook/test_node.py:505:12
-ERROR Cannot index into `object` [bad-index]
- --> tests/unit_tests/core/workflow/nodes/trigger_webhook/test_node.py:506:12
-ERROR Cannot index into `object` [bad-index]
- --> tests/unit_tests/core/workflow/nodes/trigger_webhook/test_node.py:507:12
-ERROR Cannot index into `object` [bad-index]
- --> tests/unit_tests/core/workflow/nodes/trigger_webhook/test_node.py:508:12
-ERROR Cannot index into `object` [bad-index]
- --> tests/unit_tests/core/workflow/nodes/trigger_webhook/test_node.py:509:12
-ERROR Cannot index into `object` [bad-index]
- --> tests/unit_tests/core/workflow/nodes/trigger_webhook/test_node.py:510:12
-ERROR Cannot index into `object` [bad-index]
- --> tests/unit_tests/core/workflow/nodes/trigger_webhook/test_node.py:511:12
ERROR Argument `SimpleNamespace` is not assignable to parameter `init_params` with type `InitParams` in function `core.workflow.node_factory.DifyNodeFactory.__init__` [bad-argument-type]
--> tests/unit_tests/core/workflow/test_node_factory.py:119:29
ERROR Argument `SimpleNamespace` is not assignable to parameter `runtime_state` with type `RuntimeState` in function `core.workflow.node_factory.DifyNodeFactory.__init__` [bad-argument-type]
|
Pyrefly Type Coverage
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #46438 +/- ##
=======================================
Coverage 90.39% 90.39%
=======================================
Files 6534 6534
Lines 409459 409525 +66
Branches 82225 82230 +5
=======================================
+ Hits 370116 370197 +81
+ Misses 32944 32932 -12
+ Partials 6399 6396 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…k-node-and-extract-processor # Conflicts: # api/tests/unit_tests/pyrefly.toml
| def test_webhook_node_default_config(): | ||
| def test_webhook_node_default_config() -> None: | ||
| """Test webhook node default configuration.""" | ||
| config = TriggerWebhookNode.get_default_config() |
There was a problem hiding this comment.
can we just type here? or type the origin code.
There was a problem hiding this comment.
I typed this at the source: TriggerWebhookNode.get_default_config() now returns WebhookNodeDefaultConfig, including the nested config shape. The test reads config["config"] directly, and the test-only narrowing helper is gone.
`TriggerWebhookNode.get_default_config` returned `Mapping[str, object]`, so `config["config"]` could only be inferred as `object` and the test needed a narrowing helper to read the payload it had just built. Declare the shape instead: two TypedDicts describing the returned mapping and its `config` section, and narrow the return type. The base class returns `Mapping[str, object]`, so this is a covariant override; every non-test caller annotates the result as `Mapping[str, object]` already, and none needs a change. The test then drops the helper and asserts the full documented payload rather than only `method`. Verified: pyrefly 29 errors / 0 warnings / 0 non-missing-import / 0 for this file, 114 tests pass, ruff clean.
|
Took the second option: typed the origin code.
|
…yrefly-webhook-node-and-extract-processor Resolve the `project-excludes` conflict: upstream graduated `core/workflow/test_node_runtime.py` in another PR, so that entry stays excluded, while this branch's own `core/workflow/nodes/trigger_webhook/test_node.py` stays graduated here.
There was a problem hiding this comment.
1 inline suggestion at c97ba68e54, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong.
dify-codereview
asukaminato0721
left a comment
There was a problem hiding this comment.
3 inline suggestions at 1cf09eed92, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong.
dify-codereview
Exercise parse_webhook_file rejection paths, the record-id precedence, and generate_file_var without a usable transfer method or when the file factory fails, so the patch coverage gate sees the new branches.
asukaminato0721
left a comment
There was a problem hiding this comment.
2 inline suggestions at 9dee343450, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong. 4 review threads are still unresolved.
dify-codereview
| @classmethod | ||
| @override | ||
| def get_default_config(cls, filters: Mapping[str, object] | None = None) -> Mapping[str, object]: | ||
| def get_default_config(cls, filters: Mapping[str, object] | None = None) -> WebhookNodeDefaultConfig: |
There was a problem hiding this comment.
Parse, don't validate (https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/): model this data once at the boundary as a pydantic model / dataclass / TypedDict (Model.model_validate(raw)), and pass the typed value on, instead of passing dicts around and re-checking keys and types where they are used. In a test, don't build this as an ad hoc dict[str, object]: define the shape (TypedDict / model) in the production code and import it here.
dify-codereview · parse-dont-validate Learned from an earlier review. Reply here if this is wrong.
The review asked to model the webhook file shape once at the boundary and let consumers read typed fields instead of re-checking. parse_webhook_file now drops any declared field whose value does not match the type the TypedDict declares for it (unknown keys still travel as JSON scalars via extra_items), so _webhook_file_record_id and generate_file_var can read reference/related_id/transfer_method without isinstance re-validation. WebhookNodeConfig headers/params/body use the real WebhookParameter and WebhookBodyParameter models from the node entities instead of list[object], and the default config spells method/content_type from the enums.
asukaminato0721
left a comment
There was a problem hiding this comment.
2 inline suggestions at 8b5fa73051, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong. 2 review threads are still unresolved.
dify-codereview
Replace the loose `object` annotations in the webhook file parser with precise types, and build the typed value at the boundary instead of filtering a dict and re-checking it where it is used. - Declare `WebhookFilePayload = Mapping[Hashable, JsonValue]` as the payload shape accepted by the parser and use it for `raw`. - Make the per-field predicates `TypeGuard`s over `JsonValue`, so the parser narrows each value once and never needs `object`. - Have `_parse_webhook_file_fields` return `WebhookFileDict | None` directly, so `parse_webhook_file` no longer builds the typed dict from a `dict[str, Any]` via `**kwargs`. - Type the test fixture payload with `WebhookFilePayload` instead of an ad hoc dict.
asukaminato0721
left a comment
There was a problem hiding this comment.
1 inline suggestion at 66d62952b7, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong. 2 review threads are still unresolved.
dify-codereview
| JSON scalars) as a ``WebhookFileDict`` when at least one survives, and ``None`` otherwise. | ||
| ``raw`` is never mutated. | ||
| """ | ||
| if not isinstance(raw, Mapping): |
There was a problem hiding this comment.
Parse, don't validate (https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/): model this data once at the boundary as a pydantic model / dataclass / TypedDict (Model.model_validate(raw)), and pass the typed value on, instead of passing dicts around and re-checking keys and types where they are used. In a test, don't build this as an ad hoc dict[str, object]: define the shape (TypedDict / model) in the production code and import it here.
dify-codereview · parse-dont-validate Learned from an earlier review. Reply here if this is wrong.
There was a problem hiding this comment.
This is the parser boundary, not a re-validation of an already trusted value. parse_webhook_file accepts untrusted WebhookFilePayload | Sequence[JsonValue] | None; the Mapping check rejects non-mapping inputs before _parse_webhook_file_fields parses the fields into a new WebhookFileDict. Callers consume that typed result without re-checking its fields, so this is an intentional boundary check.
# Conflicts: # api/tests/unit_tests/core/rag/extractor/test_extract_processor.py
asukaminato0721
left a comment
There was a problem hiding this comment.
1 inline suggestion at 26774baeb0, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong. 3 review threads are still unresolved.
dify-codereview
| session: object | None = None, | ||
| ): | ||
| session: Session | None = None, | ||
| ) -> tuple[str, tuple[object, ...], dict[str, object]]: |
There was a problem hiding this comment.
Parse, don't validate (https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/): model this data once at the boundary as a pydantic model / dataclass / TypedDict (Model.model_validate(raw)), and pass the typed value on, instead of passing dicts around and re-checking keys and types where they are used. In a test, don't build this as an ad hoc dict[str, object]: define the shape (TypedDict / model) in the production code and import it here.
dify-codereview · parse-dont-validate Learned from an earlier review. Reply here if this is wrong.
There was a problem hiding this comment.
Thanks for flagging this. The dict[str, object] here records keyword arguments passed to the monkeypatched extractor constructors. Those constructors don't share a single keyword schema, and the recorded arguments aren't the upload payload. The upload input already uses the production UploadFileExtractionInput.model_validate(...) at the boundary. Is there another production type you had in mind for the recorder?
asukaminato0721
left a comment
There was a problem hiding this comment.
Consider splitting this into smaller pull requests: it adds 186 lines of non-test code, past about 150. Split it by feature: each pull request carries one functional change together with its tests, so each feature stands on its own and can be reviewed, merged and reverted independently. A rule of thumb, not a requirement. Size counts added non-test lines; tests, lock files and snapshots do not count.
dify-codereview
Why
api/tests/unit_tests/pyrefly.tomlkeeps the strict-mode debt list. This removes two entriesand pays the debt.
What changed
core/workflow/nodes/trigger_webhook/test_node.pyruntime_state.app_config. The runtime state class does not definethat field anywhere in the repository; the tenant comes from
run_context, so the assignmentwas dead code rather than a test hook.
_mapping(value: object) -> dict[str, object]helper that narrows thedefault config before indexing, replacing nine untrusted subscripts.
methodargument; added-> Noneto the tests.core/rag/extractor/test_extract_processor.pyUploadFileExtractionInput.model_validate(...), thesame path
core/rag/extractor/extract_processor.pyuses, instead of passing a raw upload.Verification
api/with both entries removed: the two target files report 0diagnostics (was 35 and 36). Total stays at the 29
missing-importentries the local venvraises for optional dependencies, WARN is 0.
pyteston both files → 78 passed, identical to the untouched baseline.ruff check --no-cacheandruff format --no-cache --checkpass.