dify
dify copied to clipboard
refactor: replace str | None = None with str = "" in service layer
Summary
Replace unnecessary str | None = None defaults with str = "" in 15 service layer files where the parameter is checked with if param: and None has no distinct semantics from empty string.
Changes
- Updated 15 service files in
api/services/ - Each change replaces
param: str | None = Nonewithparam: str = "" - No behavioral change since all affected parameters use
if param:checks
Closes #35557
Pyrefly Diff
base → PR
--- /tmp/pyrefly_base.txt 2026-05-26 07:08:33.706777730 +0000
+++ /tmp/pyrefly_pr.txt 2026-05-26 07:08:25.153676014 +0000
@@ -1,9 +1,21 @@
+ERROR Argument `str | None` is not assignable to parameter `name` with type `str` in function `services.account_service.TenantService.create_owner_tenant_if_not_exist` [bad-argument-type]
+ --> commands/account.py:137:61
+ERROR Argument `str | None` is not assignable to parameter `keyword` with type `str` in function `services.agent.roster_service.AgentRosterService.list_roster_agents` [bad-argument-type]
+ --> controllers/console/agent/roster.py:47:78
+ERROR Argument `str | None` is not assignable to parameter `keyword` with type `str` in function `services.agent.roster_service.AgentRosterService.list_invite_options` [bad-argument-type]
+ --> controllers/console/agent/roster.py:75:21
ERROR `str` is not assignable to `Literal['advanced-chat', 'agent-chat', 'all', 'channel', 'chat', 'completion', 'workflow']` [bad-assignment]
--> controllers/console/app/app.py:69:104
ERROR Object of class `App` has no attribute `access_mode` [missing-attribute]
--> controllers/console/app/app.py:584:13
+ERROR Argument `WorkflowService` is not assignable to parameter `workflow_service` with type `WorkflowServiceInterface` in function `core.llm_generator.llm_generator.LLMGenerator.instruction_modify_workflow` [bad-argument-type]
+ --> controllers/console/app/generator.py:230:38
ERROR Argument `str | None` is not assignable to parameter `language` with type `str` in function `services.account_service.AccountService.send_email_register_email` [bad-argument-type]
--> controllers/console/auth/email_register.py:86:108
+ERROR Argument `str | None` is not assignable to parameter `keyword` with type `str` in function `services.dataset_service.SegmentService.get_child_chunks` [bad-argument-type]
+ --> controllers/console/datasets/datasets_segments.py:650:75
+ERROR Argument `str | None` is not assignable to parameter `credential_id` with type `str` in function `services.plugin.oauth_service.OAuthProxyService.create_proxy_context` [bad-argument-type]
+ --> controllers/console/datasets/rag_pipeline/datasource_auth.py:90:27
ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
--> controllers/console/init_validate.py:31:2
ERROR Object of class `MissingRouter` has no attribute `post` [missing-attribute]
@@ -14,8 +26,18 @@
--> controllers/console/setup.py:40:2
ERROR Object of class `MissingRouter` has no attribute `post` [missing-attribute]
--> controllers/console/setup.py:65:2
+ERROR Argument `str | None` is not assignable to parameter `keyword` with type `str` in function `services.tag_service.TagService.get_tags` [bad-argument-type]
+ --> controllers/console/tag/tags.py:99:67
ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
--> controllers/console/version.py:30:2
+ERROR Argument `ModelType | None` is not assignable to parameter `model_type` with type `str` in function `services.model_provider_service.ModelProviderService.get_provider_list` [bad-argument-type]
+ --> controllers/console/workspace/model_providers.py:106:98
+ERROR Argument `str | None` is not assignable to parameter `variable_name` with type `str` in function `services.conversation_service.ConversationService.get_conversational_variable` [bad-argument-type]
+ --> controllers/service_api/app/conversation.py:287:82
+ERROR Argument `str | None` is not assignable to parameter `keyword` with type `str` in function `services.dataset_service.SegmentService.get_segments` [bad-argument-type]
+ --> controllers/service_api/dataset/segment.py:219:21
+ERROR Argument `str | None` is not assignable to parameter `keyword` with type `str` in function `services.dataset_service.SegmentService.get_child_chunks` [bad-argument-type]
+ --> controllers/service_api/dataset/segment.py:491:75
ERROR Class member `EasyUIBasedGenerateTaskPipeline._application_generate_entity` overrides parent class `BasedGenerateTaskPipeline` in an inconsistent manner [bad-override-mutable-attribute]
--> core/app/task_pipeline/easy_ui_based_generate_task_pipeline.py:75:5
ERROR `+=` is not supported between `list[PromptMessageContentUnionTypes]` and `str` [unsupported-operation]
@@ -558,8 +580,16 @@
--> schedule/queue_monitor_task.py:14:21
ERROR Object of class `Tenant` has no attribute `role` [missing-attribute]
--> services/account_service.py:1355:13
+ERROR Argument `str | None` is not assignable to parameter `workflow_id` with type `str` in function `services.workflow_service.WorkflowService.get_draft_workflow` [bad-argument-type]
+ --> services/app_dsl_service.py:555:67
+ERROR Argument `Any | None` is not assignable to parameter `workflow_id` with type `str` in function `AppGenerateService._get_workflow` [bad-argument-type]
+ --> services/app_generate_service.py:154:74
+ERROR Argument `Any | None` is not assignable to parameter `workflow_id` with type `str` in function `AppGenerateService._get_workflow` [bad-argument-type]
+ --> services/app_generate_service.py:211:74
ERROR `+` is not supported between `str` and `dict[Unknown, Unknown]` [unsupported-operation]
--> services/app_service.py:519:53
+ERROR Argument `str | None` is not assignable to parameter `workflow_id` with type `str` in function `AsyncWorkflowService._get_workflow` [bad-argument-type]
+ --> services/async_workflow_service.py:92:67
ERROR No matching overload found for function `flask.helpers.stream_with_context` called with arguments: (Generator[bytes]) [no-matching-overload]
--> services/audio_service.py:144:56
ERROR No matching overload found for function `flask.helpers.stream_with_context` called with arguments: (Generator[bytes]) [no-matching-overload]
@@ -568,6 +598,8 @@
--> services/conversation_service.py:131:33
ERROR `dict[str, dict[str, Any] | str | None]` is not assignable to variable `data_source_info` with type `dict[str, bool | str]` [bad-assignment]
--> services/dataset_service.py:2232:56
+ERROR Argument `str | None` is not assignable to parameter `document_id` with type `str` in function `DocumentService.get_document` [bad-argument-type]
+ --> services/dataset_service.py:2675:61
ERROR `dict[str, dict[str, Any] | str | None]` is not assignable to variable `data_source_info` with type `dict[str, bool | str]` [bad-assignment]
--> services/dataset_service.py:2745:44
ERROR `None` is not assignable to attribute `rules` with type `Never` [bad-assignment]
@@ -582,12 +614,18 @@
--> services/document_indexing_proxy/duplicate_document_indexing_task_proxy.py:15:5
ERROR `handled_tenant_count` was assigned in the current scope before the nonlocal declaration [unknown-name]
--> services/plugin/plugin_migration.py:93:34
+ERROR Argument `str | None` is not assignable to parameter `credential_id` with type `str` in function `services.datasource_provider_service.DatasourceProviderService.get_datasource_credentials` [bad-argument-type]
+ --> services/rag_pipeline/rag_pipeline.py:656:31
+ERROR Argument `str | None` is not assignable to parameter `credential_id` with type `str` in function `services.datasource_provider_service.DatasourceProviderService.get_datasource_credentials` [bad-argument-type]
+ --> services/rag_pipeline/rag_pipeline.py:801:31
ERROR `dict[str, Any]` is not assignable to attribute `credentials` with type `Never` [bad-assignment]
--> services/trigger/trigger_provider_service.py:487:40
ERROR `int` is not assignable to attribute `credential_expires_at` with type `Never` [bad-assignment]
--> services/trigger/trigger_provider_service.py:488:50
ERROR Object of class `dict` has no attribute `encode`
ERROR Object of class `dict` has no attribute `encode`
+ERROR Argument `Any | None` is not assignable to parameter `credential_id` with type `str` in function `services.datasource_provider_service.DatasourceProviderService.get_datasource_credentials` [bad-argument-type]
+ --> tasks/document_indexing_sync_task.py:78:23
ERROR `Literal['error']` is not assignable to attribute `status` with type `Never` [bad-assignment]
--> tasks/regenerate_summary_index_task.py:276:61
ERROR `str` is not assignable to attribute `error` with type `Never` [bad-assignment]
@@ -1094,6 +1132,8 @@
--> tests/test_containers_integration_tests/services/test_dataset_service_delete_dataset.py:25:20
ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
--> tests/test_containers_integration_tests/services/test_dataset_service_delete_dataset.py:32:20
+ERROR Argument `None` is not assignable to parameter `document_id` with type `str` in function `services.dataset_service.DocumentService.get_document` [bad-argument-type]
+ --> tests/test_containers_integration_tests/services/test_dataset_service_document.py:126:53
ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
--> tests/test_containers_integration_tests/services/test_dataset_service_permissions.py:38:20
ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
@@ -6408,6 +6448,8 @@
--> tests/unit_tests/services/test_model_load_balancing_service.py:673:37
ERROR `(tenant_id: str) -> service_with_fake_configurations._FakeProviderManager` is not assignable to attribute `_get_provider_manager` with type `(tenant_id: str) -> ProviderManager` [bad-assignment]
--> tests/unit_tests/services/test_model_provider_service_sanitization.py:74:33
+ERROR Argument `None` is not assignable to parameter `model_type` with type `str` in function `services.model_provider_service.ModelProviderService.get_provider_list` [bad-argument-type]
+ --> tests/unit_tests/services/test_model_provider_service_sanitization.py:79:101
ERROR Argument `frozenset[str]` is not assignable to parameter `scopes` with type `frozenset[Scope]` in function `libs.oauth_bearer.AuthContext.__init__` [bad-argument-type]
--> tests/unit_tests/services/test_oauth_device_flow.py:22:16
ERROR Argument `frozenset[str]` is not assignable to parameter `scopes` with type `frozenset[Scope]` in function `libs.oauth_bearer.AuthContext.__init__` [bad-argument-type]
Pyrefly Type Coverage
| Metric | Base | PR | Delta |
|---|---|---|---|
| Type coverage | 45.48% | 45.48% | 0.00% |
| Strict coverage | 45.00% | 45.00% | 0.00% |
| Typed symbols | 23,980 | 23,980 | 0 |
| Untyped symbols | 29,056 | 29,056 | 0 |
| Modules | 2709 | 2709 | 0 |
@asukaminato0721
Hi @EvanYao826, thank you for your contribution. This issue already has an earlier linked PR (#36223), 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!