fix: merge retrieval_model with defaults to handle legacy rows
Summary
Fixes #36722
Legacy dataset rows may have retrieval_model stored with only a subset of keys (e.g. missing search_method, reranking_enable). When the model is returned without these keys, downstream Pydantic validation in DatasetDetailResponse fails:
pydantic_core._pydantic_core.ValidationError: 2 validation errors for DatasetDetailResponse
search_method
Field required
reranking_enable
Field required
Changes
api/models/dataset.py: Changedretrieval_model_dictproperty to merge stored values with defaults using{**defaults, **stored}. This ensures missing keys are filled while preserving stored values.api/tests/unit_tests/models/test_dataset_models.py: Added two regression tests:test_dataset_retrieval_model_dict_merges_with_defaults— verifies legacy rows get missing keys filledtest_dataset_retrieval_model_dict_stored_values_override_defaults— verifies stored values take precedence
Root Cause
The retrieval_model_dict property used self.retrieval_model or default_retrieval_model, which returns the stored dict as-is when it's non-empty. If the stored dict is missing newly-added keys (from schema evolution), Pydantic validation fails downstream.
From Hermes Agent
Pyrefly Diff
base → PR
--- /tmp/pyrefly_base.txt 2026-05-28 08:37:42.881265933 +0000
+++ /tmp/pyrefly_pr.txt 2026-05-28 08:37:29.603140120 +0000
@@ -6110,13 +6110,13 @@
ERROR Argument `dict[str, bool | str]` is not assignable to parameter `value` with type `TenantCustomConfigDict` in function `models.account.Tenant.custom_config_dict` [bad-argument-type]
--> tests/unit_tests/models/test_account_models.py:573:37
ERROR `None` is not subscriptable [unsupported-operation]
- --> tests/unit_tests/models/test_dataset_models.py:150:16
-ERROR `None` is not subscriptable [unsupported-operation]
--> tests/unit_tests/models/test_dataset_models.py:151:16
+ERROR `None` is not subscriptable [unsupported-operation]
+ --> tests/unit_tests/models/test_dataset_models.py:152:16
ERROR `in` is not supported between `Literal['pre_processing_rules']` and `None` [not-iterable]
- --> tests/unit_tests/models/test_dataset_models.py:887:16
+ --> tests/unit_tests/models/test_dataset_models.py:934:16
ERROR `in` is not supported between `Literal['segmentation']` and `None` [not-iterable]
- --> tests/unit_tests/models/test_dataset_models.py:888:16
+ --> tests/unit_tests/models/test_dataset_models.py:935:16
ERROR Argument `Literal['llm']` is not assignable to parameter `model_type` with type `ModelType | SQLCoreOperations[ModelType]` in function `models.provider.ProviderModel.__init__` [bad-argument-type]
--> tests/unit_tests/models/test_provider_models.py:296:24
ERROR Argument `Literal['llm']` is not assignable to parameter `model_type` with type `ModelType | SQLCoreOperations[ModelType]` in function `models.provider.ProviderModel.__init__` [bad-argument-type]
Pyrefly Type Coverage
| Metric | Base | PR | Delta |
|---|---|---|---|
| Type coverage | 45.74% | 45.74% | -0.00% |
| Strict coverage | 45.27% | 45.27% | -0.00% |
| Typed symbols | 24,619 | 24,619 | 0 |
| Untyped symbols | 29,508 | 29,510 | +2 |
| Modules | 2758 | 2758 | 0 |
Hi @EvanYao826, thank you for your contribution. This issue already has an earlier linked PR (#36753), and according to our FIFO standard we proceed with the first PR for an issue. I am closing this PR to keep the review queue focused. We appreciate your work and hope you will continue contributing. Thanks!