[PR #24542] fix infinite loop when clean unused dataset #30682

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

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

State: closed
Merged: Yes


Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

Fixes #24433

  1. Added page tracking: Initialize page = 1 and increment after each batch
  2. Fixed pagination call: Use dynamic page=page instead of hardcoded page=1
  3. Handle pagination errors: Added error_out=False to prevent 404 errors on empty pages
  4. Improved exit condition: Check for None datasets to handle edge cases

Screenshots

Before After
... ...

Reproduction Steps

  1. Insert Test Data to database
-- insert dataset
INSERT INTO datasets (
id, tenant_id, name, provider, permission, data_source_type, indexing_technique, created_by, created_at, updated_at
) VALUES (
gen_random_uuid(), 'your-tenant-uuid', 'test_dataset', 'vendor', 'only_me', 'upload_file', 'high_quality', 'your-user-uuid', '2023-12-01 00:00:00', '2023-12-01 00:00:00'
);

-- insert document
INSERT INTO documents (
id, tenant_id, dataset_id, position, data_source_type, batch, name, created_from, created_by, created_at, indexing_status, enabled, archived, updated_at
) VALUES (
gen_random_uuid(), 'your-tenant-uuid', 'your-dataset-uuid', 1, 'upload_file', 'batch1', 'test_document', 'manual', 'your-user-uuid', '2023-12-01 00:00:00', 'completed', true, false, '2023-12-01 00:00:00'
);
  1. Modify ext_celery Configuration

Edit extensions/ext_celery.py to enable the task:

if dify_config.ENABLE_CLEAN_UNUSED_DATASETS_TASK:
        imports.append("schedule.clean_unused_datasets_task")
        beat_schedule["clean_unused_datasets_task"] = {
            "task": "schedule.clean_unused_datasets_task.clean_unused_datasets_task",
-          "schedule": crontab(minute="0", hour="3", day_of_month=f"*/{day}"),
+           "schedule": crontab(minute="*"),
        }
  1. Start Celery Beat and Worker
# shoule config env ENABLE_CLEAN_UNUSED_DATASETS_TASK=true
uv run celery -A app.celery beat --loglevel=info
uv run celery -A app.celery worker -P gevent -c 1 --loglevel INFO -Q dataset,generation,mail,ops_trace
  • 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 dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/24542 **State:** closed **Merged:** Yes --- > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary Fixes #24433 1. Added page tracking: Initialize page = 1 and increment after each batch 2. Fixed pagination call: Use dynamic page=page instead of hardcoded page=1 3. Handle pagination errors: Added error_out=False to prevent 404 errors on empty pages 4. Improved exit condition: Check for None datasets to handle edge cases <!-- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. --> ## Screenshots | Before | After | |--------|-------| | ... | ... | ### Reproduction Steps 1. Insert Test Data to database ```sql -- insert dataset INSERT INTO datasets ( id, tenant_id, name, provider, permission, data_source_type, indexing_technique, created_by, created_at, updated_at ) VALUES ( gen_random_uuid(), 'your-tenant-uuid', 'test_dataset', 'vendor', 'only_me', 'upload_file', 'high_quality', 'your-user-uuid', '2023-12-01 00:00:00', '2023-12-01 00:00:00' ); -- insert document INSERT INTO documents ( id, tenant_id, dataset_id, position, data_source_type, batch, name, created_from, created_by, created_at, indexing_status, enabled, archived, updated_at ) VALUES ( gen_random_uuid(), 'your-tenant-uuid', 'your-dataset-uuid', 1, 'upload_file', 'batch1', 'test_document', 'manual', 'your-user-uuid', '2023-12-01 00:00:00', 'completed', true, false, '2023-12-01 00:00:00' ); ``` 2. Modify ext_celery Configuration Edit extensions/ext_celery.py to enable the task: ```diff if dify_config.ENABLE_CLEAN_UNUSED_DATASETS_TASK: imports.append("schedule.clean_unused_datasets_task") beat_schedule["clean_unused_datasets_task"] = { "task": "schedule.clean_unused_datasets_task.clean_unused_datasets_task", - "schedule": crontab(minute="0", hour="3", day_of_month=f"*/{day}"), + "schedule": crontab(minute="*"), } ``` 3. Start Celery Beat and Worker ``` # shoule config env ENABLE_CLEAN_UNUSED_DATASETS_TASK=true uv run celery -A app.celery beat --loglevel=info uv run celery -A app.celery worker -P gevent -c 1 --loglevel INFO -Q dataset,generation,mail,ops_trace ``` - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:48:01 -05:00
yindo closed this issue 2026-02-21 20:48:01 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#30682