Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

ci: enable Ruff B007 (#44107)

Asuka Minatoe9e032514c7f
diff --git a/api/.ruff.toml b/api/.ruff.toml
index 291e98c3d9e..9a6e9a610d2 100644
--- a/api/.ruff.toml
+++ b/api/.ruff.toml
@@ -62,7 +62,6 @@ ignore = [
"F821", # undefined-name
"F841", # unused-variable
"UP007", # non-pep604-annotation
- "B007", # unused-loop-control-variable
"B901", # allow return in yield
"B903", # class-as-data-structure
"B904", # raise-without-from-inside-except
diff --git a/api/extensions/storage/clickzetta_volume/file_lifecycle.py b/api/extensions/storage/clickzetta_volume/file_lifecycle.py
index 1cb940b797b..4943114ac08 100644
--- a/api/extensions/storage/clickzetta_volume/file_lifecycle.py
+++ b/api/extensions/storage/clickzetta_volume/file_lifecycle.py
@@ -372,14 +372,14 @@ class FileLifecycleManager:
continue
# Cleanup old versions for each file
- for base_filename, versions in file_versions.items():
+ for _base_filename, versions in file_versions.items():
# Sort by version number
versions.sort(key=operator.itemgetter(0), reverse=True)
# Keep the newest max_versions versions, delete the rest
if len(versions) > max_versions:
to_delete = versions[max_versions:]
- for version_num, version_file in to_delete:
+ for _version_num, version_file in to_delete:
self._storage.delete(version_file)
cleaned_count += 1
logger.debug("Cleaned old version: %s", version_file)
diff --git a/api/repositories/app/console_repository.py b/api/repositories/app/console_repository.py
index aede4f8a5be..64fa0844d09 100644
--- a/api/repositories/app/console_repository.py
+++ b/api/repositories/app/console_repository.py
@@ -346,14 +346,14 @@ class ConsoleAppRepository(ConsoleApps, DiscoveryApps, RelatedApps):
)
)
for workflow in workflows:
- node_id = None
+ _node_id = None
try:
- for node_id, node_data in workflow.walk_nodes():
+ for _node_id, node_data in workflow.walk_nodes():
if node_data.get("type") in TRIGGER_NODE_TYPES:
result.add(workflow.app_id)
break
except Exception:
- logger.exception("error while walking nodes, workflow_id=%s, node_id=%s", workflow.id, node_id)
+ logger.exception("error while walking nodes, workflow_id=%s, node_id=%s", workflow.id, _node_id)
return result
@staticmethod
diff --git a/api/tests/test_containers_integration_tests/core/rag/pipeline/test_queue_integration.py b/api/tests/test_containers_integration_tests/core/rag/pipeline/test_queue_integration.py
index d1af0a56ef2..c77cdd02240 100644
--- a/api/tests/test_containers_integration_tests/core/rag/pipeline/test_queue_integration.py
+++ b/api/tests/test_containers_integration_tests/core/rag/pipeline/test_queue_integration.py
@@ -355,7 +355,7 @@ class TestTenantIsolatedTaskQueueIntegration:
"""Test realistic batch processing scenario."""
# Simulate batch processing tasks
batch_tasks = []
- for i in range(3):
+ for _i in range(3):
task = {
"file_id": str(uuid4()),
"tenant_id": test_queue._tenant_id,
diff --git a/api/tests/test_containers_integration_tests/libs/broadcast_channel/redis/test_channel.py b/api/tests/test_containers_integration_tests/libs/broadcast_channel/redis/test_channel.py
index 8086d52191b..c52bf2ce860 100644
--- a/api/tests/test_containers_integration_tests/libs/broadcast_channel/redis/test_channel.py
+++ b/api/tests/test_containers_integration_tests/libs/broadcast_channel/redis/test_channel.py
@@ -325,11 +325,11 @@ class TestRedisBroadcastChannelIntegration:
topic = broadcast_channel.topic(topic_name)
def _consume(sub: Subscription):
- for i in sub:
+ for _i in sub:
pass
subscriptions = []
- for i in range(5):
+ for _i in range(5):
subscription = topic.subscribe()
subscriptions.append(subscription)
diff --git a/api/tests/test_containers_integration_tests/services/test_message_service.py b/api/tests/test_containers_integration_tests/services/test_message_service.py
index 32456f02698..d26ee1c530f 100644
--- a/api/tests/test_containers_integration_tests/services/test_message_service.py
+++ b/api/tests/test_containers_integration_tests/services/test_message_service.py
@@ -207,7 +207,7 @@ class TestMessageService:
# Create a conversation and multiple messages
conversation = self._create_test_conversation(db_session_with_containers, app, account, fake)
messages = []
- for i in range(5):
+ for _i in range(5):
message = self._create_test_message(db_session_with_containers, app, conversation, account, fake)
messages.append(message)
@@ -314,7 +314,7 @@ class TestMessageService:
# Create a conversation and multiple messages
conversation = self._create_test_conversation(db_session_with_containers, app, account, fake)
messages = []
- for i in range(5):
+ for _i in range(5):
message = self._create_test_message(db_session_with_containers, app, conversation, account, fake)
messages.append(message)
@@ -348,7 +348,7 @@ class TestMessageService:
# Create a conversation and multiple messages
conversation = self._create_test_conversation(db_session_with_containers, app, account, fake)
messages = []
- for i in range(5):
+ for _i in range(5):
message = self._create_test_message(db_session_with_containers, app, conversation, account, fake)
messages.append(message)
diff --git a/api/tests/test_containers_integration_tests/services/test_messages_clean_service.py b/api/tests/test_containers_integration_tests/services/test_messages_clean_service.py
index 2af90d0ef2a..07cd578a207 100644
--- a/api/tests/test_containers_integration_tests/services/test_messages_clean_service.py
+++ b/api/tests/test_containers_integration_tests/services/test_messages_clean_service.py
@@ -414,7 +414,7 @@ class TestMessagesCleanServiceIntegration:
# Arrange - Create sandbox tenants with expired messages
sandbox_tenants = []
sandbox_message_ids = []
- for i in range(2):
+ for _i in range(2):
account, tenant = self._create_account_and_tenant(db_session_with_containers, plan=CloudPlan.SANDBOX)
sandbox_tenants.append(tenant)
app = self._create_app(db_session_with_containers, tenant, account)
@@ -431,7 +431,7 @@ class TestMessagesCleanServiceIntegration:
# Create paid tenants with expired messages (should NOT be deleted)
paid_tenants = []
paid_message_ids = []
- for i in range(2):
+ for _i in range(2):
account, tenant = self._create_account_and_tenant(db_session_with_containers, plan=CloudPlan.PROFESSIONAL)
paid_tenants.append(tenant)
app = self._create_app(db_session_with_containers, tenant, account)
@@ -605,7 +605,7 @@ class TestMessagesCleanServiceIntegration:
"""Test when billing returns partial data, unknown tenants are preserved (B5)."""
# Arrange - Create 3 tenants
tenants_data = []
- for i in range(3):
+ for _i in range(3):
account, tenant = self._create_account_and_tenant(db_session_with_containers, plan=CloudPlan.SANDBOX)
app = self._create_app(db_session_with_containers, tenant, account)
conv = self._create_conversation(db_session_with_containers, app)
@@ -920,7 +920,7 @@ class TestMessagesCleanServiceIntegration:
"""Test that whitelisted tenants' messages are not deleted (B9)."""
# Arrange - Create 3 sandbox tenants with expired messages
tenants_data = []
- for i in range(3):
+ for _i in range(3):
account, tenant = self._create_account_and_tenant(db_session_with_containers, plan=CloudPlan.SANDBOX)
app = self._create_app(db_session_with_containers, tenant, account)
conv = self._create_conversation(db_session_with_containers, app)
diff --git a/api/tests/test_containers_integration_tests/services/test_web_conversation_service.py b/api/tests/test_containers_integration_tests/services/test_web_conversation_service.py
index a0ece2a2eff..76dc411451a 100644
--- a/api/tests/test_containers_integration_tests/services/test_web_conversation_service.py
+++ b/api/tests/test_containers_integration_tests/services/test_web_conversation_service.py
@@ -168,7 +168,7 @@ class TestWebConversationService:
# Create multiple conversations
conversations = []
- for i in range(5):
+ for _i in range(5):
conversation = self._create_test_conversation(db_session_with_containers, app, account, fake)
conversations.append(conversation)
@@ -204,7 +204,7 @@ class TestWebConversationService:
# Create conversations
conversations = []
- for i in range(5):
+ for _i in range(5):
conversation = self._create_test_conversation(db_session_with_containers, app, account, fake)
conversations.append(conversation)
@@ -259,7 +259,7 @@ class TestWebConversationService:
# Create conversations
conversations = []
- for i in range(5):
+ for _i in range(5):
conversation = self._create_test_conversation(db_session_with_containers, app, account, fake)
conversations.append(conversation)
diff --git a/api/tests/test_containers_integration_tests/services/test_workflow_draft_variable_service.py b/api/tests/test_containers_integration_tests/services/test_workflow_draft_variable_service.py
index 82fe391b08a..4cef1d30ffa 100644
--- a/api/tests/test_containers_integration_tests/services/test_workflow_draft_variable_service.py
+++ b/api/tests/test_containers_integration_tests/services/test_workflow_draft_variable_service.py
@@ -293,7 +293,7 @@ class TestWorkflowDraftVariableService:
"""
fake = Faker()
app = self._create_test_app(db_session_with_containers, mock_external_service_dependencies, fake=fake)
- for i in range(5):
+ for _i in range(5):
test_value = StringSegment(value=fake.numerify("value######"))
self._create_test_variable(
db_session_with_containers,
@@ -547,7 +547,7 @@ class TestWorkflowDraftVariableService:
"""
fake = Faker()
app = self._create_test_app(db_session_with_containers, mock_external_service_dependencies, fake=fake)
- for i in range(3):
+ for _i in range(3):
test_value = StringSegment(value=fake.numerify("value######"))
self._create_test_variable(
db_session_with_containers,
@@ -660,7 +660,7 @@ class TestWorkflowDraftVariableService:
fake = Faker()
app = self._create_test_app(db_session_with_containers, mock_external_service_dependencies, fake=fake)
node_id = fake.word()
- for i in range(2):
+ for _i in range(2):
test_value = StringSegment(value=fake.numerify("node_value######"))
self._create_test_variable(
db_session_with_containers,
diff --git a/api/tests/test_containers_integration_tests/services/test_workflow_run_service.py b/api/tests/test_containers_integration_tests/services/test_workflow_run_service.py
index f24cc6f772a..18d204998c5 100644
--- a/api/tests/test_containers_integration_tests/services/test_workflow_run_service.py
+++ b/api/tests/test_containers_integration_tests/services/test_workflow_run_service.py
@@ -242,7 +242,7 @@ class TestWorkflowRunService:
# Create multiple workflow runs
workflow_runs = []
- for i in range(5):
+ for _i in range(5):
workflow_run = self._create_test_workflow_run(db_session_with_containers, app, account, "debugging")
workflow_runs.append(workflow_run)
diff --git a/api/tests/test_containers_integration_tests/tasks/test_batch_clean_document_task.py b/api/tests/test_containers_integration_tests/tasks/test_batch_clean_document_task.py
index 574ba58b742..9476bd9a0c0 100644
--- a/api/tests/test_containers_integration_tests/tasks/test_batch_clean_document_task.py
+++ b/api/tests/test_containers_integration_tests/tasks/test_batch_clean_document_task.py
@@ -492,7 +492,7 @@ class TestBatchCleanDocumentTask:
upload_files = []
# Create 3 documents with segments and files
- for i in range(3):
+ for _i in range(3):
document = self._create_test_document(db_session_with_containers, dataset, account)
segment = self._create_test_document_segment(db_session_with_containers, document, account)
upload_file = self._create_test_upload_file(db_session_with_containers, account)
@@ -629,7 +629,7 @@ class TestBatchCleanDocumentTask:
# Create 10 documents with segments and files (larger batch)
batch_size = 10
- for i in range(batch_size):
+ for _i in range(batch_size):
document = self._create_test_document(db_session_with_containers, dataset, account)
segment = self._create_test_document_segment(db_session_with_containers, document, account)
upload_file = self._create_test_upload_file(db_session_with_containers, account)
diff --git a/api/tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py b/api/tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py
index ee47693ee66..d311cbfc4c8 100644
--- a/api/tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py
+++ b/api/tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py
@@ -364,7 +364,7 @@ class TestCleanDatasetTask:
# Create multiple documents
documents = []
- for i in range(3):
+ for _i in range(3):
document = self._create_test_document(db_session_with_containers, account, tenant, dataset)
documents.append(document)
@@ -693,12 +693,12 @@ class TestCleanDatasetTask:
upload_file_ids = []
# Create 50 documents with segments and upload files
- for i in range(50):
+ for _i in range(50):
document = self._create_test_document(db_session_with_containers, account, tenant, dataset)
documents.append(document)
# Create 3 segments per document
- for j in range(3):
+ for _j in range(3):
segment = self._create_test_segment(db_session_with_containers, account, tenant, dataset, document)
segments.append(segment)
diff --git a/api/tests/test_containers_integration_tests/tasks/test_create_segment_to_index_task.py b/api/tests/test_containers_integration_tests/tasks/test_create_segment_to_index_task.py
index aa4257bdb05..b9bd0721643 100644
--- a/api/tests/test_containers_integration_tests/tasks/test_create_segment_to_index_task.py
+++ b/api/tests/test_containers_integration_tests/tasks/test_create_segment_to_index_task.py
@@ -650,7 +650,7 @@ class TestCreateSegmentToIndexTask:
dataset, document = self._create_test_dataset_and_document(db_session_with_containers, tenant.id, account.id)
segments = []
- for i in range(3):
+ for _i in range(3):
segment = self._create_test_segment(
db_session_with_containers, dataset.id, document.id, tenant.id, account.id, status=SegmentStatus.WAITING
)
@@ -1087,7 +1087,7 @@ class TestCreateSegmentToIndexTask:
# Create multiple segments with different characteristics
segments = []
- for i in range(5):
+ for _i in range(5):
segment = self._create_test_segment(
db_session_with_containers, dataset.id, document.id, tenant.id, account.id, status=SegmentStatus.WAITING
)
diff --git a/api/tests/test_containers_integration_tests/tasks/test_disable_segment_from_index_task.py b/api/tests/test_containers_integration_tests/tasks/test_disable_segment_from_index_task.py
index 1d8fcc6b5d7..e0dd84ee67e 100644
--- a/api/tests/test_containers_integration_tests/tasks/test_disable_segment_from_index_task.py
+++ b/api/tests/test_containers_integration_tests/tasks/test_disable_segment_from_index_task.py
@@ -608,7 +608,7 @@ class TestDisableSegmentFromIndexTask:
document = self._create_test_document(db_session_with_containers, dataset, tenant, account)
segments = []
- for i in range(3):
+ for _i in range(3):
segment = self._create_test_segment(db_session_with_containers, document, dataset, tenant, account)
segments.append(segment)
diff --git a/api/tests/test_containers_integration_tests/test_workflow_pause_integration.py b/api/tests/test_containers_integration_tests/test_workflow_pause_integration.py
index 6402e7da2bd..d9bbf54150c 100644
--- a/api/tests/test_containers_integration_tests/test_workflow_pause_integration.py
+++ b/api/tests/test_containers_integration_tests/test_workflow_pause_integration.py
@@ -646,7 +646,7 @@ class TestWorkflowPauseIntegration:
pause_entities = []
repository = self._get_workflow_run_repository()
- for i in range(5):
+ for _i in range(5):
workflow_run = self._create_test_workflow_run()
test_state = self._create_test_state()
diff --git a/api/tests/unit_tests/core/datasource/test_file_upload.py b/api/tests/unit_tests/core/datasource/test_file_upload.py
index 18c9b6c3924..130036b249e 100644
--- a/api/tests/unit_tests/core/datasource/test_file_upload.py
+++ b/api/tests/unit_tests/core/datasource/test_file_upload.py
@@ -1026,7 +1026,7 @@ class TestMimeTypeHandling:
fallback_mime = "application/octet-stream"
# Act & Assert - All unknown types should use fallback
- for ext in unknown_extensions:
+ for _ext in unknown_extensions:
# In real implementation, unknown types would use fallback
assert fallback_mime == "application/octet-stream"
diff --git a/api/tests/unit_tests/utils/encryption/test_system_encryption.py b/api/tests/unit_tests/utils/encryption/test_system_encryption.py
index 327847e1e32..f9e2c9d8143 100644
--- a/api/tests/unit_tests/utils/encryption/test_system_encryption.py
+++ b/api/tests/unit_tests/utils/encryption/test_system_encryption.py
@@ -608,7 +608,7 @@ class TestPerformance:
params = {"client_id": "test_id", "client_secret": "test_secret"}
# Test multiple rounds of encryption/decryption
- for i in range(100):
+ for _i in range(100):
encrypted = encrypter.encrypt_params(params)
decrypted = encrypter.decrypt_params(encrypted)
assert decrypted == params