Skip to content

refactor: use MetadataFilteringCondition BaseModel in RetrievalService.external_retrieve#35869

Draft
gaurav0107 wants to merge 1 commit intolanggenius:mainfrom
gaurav0107:fix/31497-retrieval-service-metadata-basemodel
Draft

refactor: use MetadataFilteringCondition BaseModel in RetrievalService.external_retrieve#35869
gaurav0107 wants to merge 1 commit intolanggenius:mainfrom
gaurav0107:fix/31497-retrieval-service-metadata-basemodel

Conversation

@gaurav0107
Copy link
Copy Markdown

Fixes part of #31497.

Summary

Follow the dict -> Pydantic BaseModel pattern established by #31514, #34080, and #34422: RetrievalService.external_retrieve now accepts metadata_filtering_conditions: MetadataFilteringCondition | None directly instead of dict[str, Any] | None.

The redundant internal MetadataFilteringCondition.model_validate(...) call is removed; validation now happens at the call site (HitTestingService.external_retrieve), following the "validate at the boundary" principle cited in the issue.

Unit tests are updated to pass typed instances where appropriate, and a regression test is added for the None path. Behavior is otherwise preserved. external_retrieval_model is left as dict[str, Any] because it is an opaque payload forwarded to external retrieval providers (no single BaseModel describes the union of provider-specific options).

Screenshots

Before After
N/A (refactor, no UI change) N/A (refactor, no UI change)

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and cd web && pnpm exec vp staged (frontend) to appease the lint gods

…e.external_retrieve

Follow the dict -> Pydantic BaseModel pattern established by langgenius#31514, langgenius#34080
and langgenius#34422: RetrievalService.external_retrieve now accepts
metadata_filtering_conditions: MetadataFilteringCondition | None directly
instead of dict[str, Any] | None.

The redundant internal MetadataFilteringCondition.model_validate(...) call
is removed; validation now happens at the call site in
HitTestingService.external_retrieve, following the "validate at the
boundary" principle cited in the issue.

Unit tests are updated to pass typed instances where appropriate and a
regression test is added for the None path. Behavior is otherwise
preserved. external_retrieval_model is left as dict[str, Any] because it
is an opaque payload forwarded to external retrieval providers.

Fixes part of langgenius#31497.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-05-07 06:31:55.825147961 +0000
+++ /tmp/pyrefly_pr.txt	2026-05-07 06:31:46.255042949 +0000
@@ -5875,15 +5875,15 @@
 ERROR Cannot index into `object` [bad-index]
    --> tests/unit_tests/services/hit_service.py:462:16
 ERROR Cannot index into `list[Unknown]` [bad-index]
-   --> tests/unit_tests/services/hit_service.py:497:20
+   --> tests/unit_tests/services/hit_service.py:503:20
 ERROR Cannot index into `object` [bad-index]
-   --> tests/unit_tests/services/hit_service.py:497:20
+   --> tests/unit_tests/services/hit_service.py:503:20
 ERROR Argument `dict[str, str] | list[Unknown] | object` is not assignable to parameter `obj` with type `Sized` in function `len` [bad-argument-type]
-   --> tests/unit_tests/services/hit_service.py:498:24
+   --> tests/unit_tests/services/hit_service.py:504:24
 ERROR Cannot index into `list[Unknown]` [bad-index]
-   --> tests/unit_tests/services/hit_service.py:531:20
+   --> tests/unit_tests/services/hit_service.py:539:20
 ERROR Cannot index into `object` [bad-index]
-   --> tests/unit_tests/services/hit_service.py:531:20
+   --> tests/unit_tests/services/hit_service.py:539:20
 ERROR Object of class `Marketplace` has no attribute `repo`
 ERROR Object of class `FunctionType` has no attribute `call_args` [missing-attribute]
   --> tests/unit_tests/services/plugin/test_oauth_service.py:50:34

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

Successfully merging this pull request may close these issues.

1 participant