[PR #10258] fix: handle KeyError when accessing rules in CleanProcessor.clean #26742

Closed
opened 2026-02-21 20:40:10 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/10258

State: closed
Merged: Yes


fix: handle KeyError when accessing rules in CleanProcessor.clean

Checklist

  • Please open an issue before creating a PR or link to an existing issue
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

Description

Fixed a KeyError that occurs when calling /console/api/datasets/indexing-estimate endpoint. The issue happens because CleanProcessor.clean() tries to access process_rule["rules"] when the rules parameter passed in is already the processed rules data.

The fix modifies the CleanProcessor.clean() method to directly use the passed rules parameter instead of trying to extract it from a process_rule dictionary, which maintains compatibility while fixing the KeyError.

Fixes #<issue_number>

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Testing Instructions

  1. API Route Test
# Test the indexing-estimate endpoint
response = client.post("/console/api/datasets/indexing-estimate", 
    json={
        "text": "sample text",
        "rules": {}
    }
)
assert response.status_code == 200
  1. CleanProcessor Test
# Test direct rules passing
result = CleanProcessor.clean("test text", rules={})
assert result == "expected output"

# Test backward compatibility
result = CleanProcessor.clean("test text", {"rules": {}})
assert result == "expected output"

# Test with None rules
result = CleanProcessor.clean("test text", rules=None)
assert result == "test text"
  1. Integration Test
  • Tested with both direct rules passing and process_rule object passing to ensure backward compatibility
  • Verified no KeyError occurs in either case
  • Confirmed text cleaning still works as expected

Please test these scenarios to verify the fix works as intended.

**Original Pull Request:** https://github.com/langgenius/dify/pull/10258 **State:** closed **Merged:** Yes --- fix: handle KeyError when accessing rules in CleanProcessor.clean # Checklist - [x] Please open an issue before creating a PR or link to an existing issue - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods # Description Fixed a KeyError that occurs when calling `/console/api/datasets/indexing-estimate` endpoint. The issue happens because `CleanProcessor.clean()` tries to access `process_rule["rules"]` when the `rules` parameter passed in is already the processed rules data. The fix modifies the `CleanProcessor.clean()` method to directly use the passed rules parameter instead of trying to extract it from a process_rule dictionary, which maintains compatibility while fixing the KeyError. Fixes #<issue_number> ## Type of Change - [x] Bug fix (non-breaking change which fixes an issue) # Testing Instructions 1. API Route Test ```python # Test the indexing-estimate endpoint response = client.post("/console/api/datasets/indexing-estimate", json={ "text": "sample text", "rules": {} } ) assert response.status_code == 200 ``` 2. CleanProcessor Test ```python # Test direct rules passing result = CleanProcessor.clean("test text", rules={}) assert result == "expected output" # Test backward compatibility result = CleanProcessor.clean("test text", {"rules": {}}) assert result == "expected output" # Test with None rules result = CleanProcessor.clean("test text", rules=None) assert result == "test text" ``` 3. Integration Test - Tested with both direct rules passing and process_rule object passing to ensure backward compatibility - Verified no KeyError occurs in either case - Confirmed text cleaning still works as expected Please test these scenarios to verify the fix works as intended.
yindo added the pull-request label 2026-02-21 20:40:10 -05:00
yindo closed this issue 2026-02-21 20:40:10 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#26742