[PR #32012] fix(api): return proper HTTP 204 status code in DELETE endpoints #33505

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

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

State: closed
Merged: Yes


Pull Request

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

close https://github.com/langgenius/dify/issues/32011

This PR fixes a bug where Flask DELETE endpoints were returning the integer 204 as the response body instead of HTTP 204 No Content status code. In Flask, returning a single integer value like return 204 causes Flask to treat it as the response body rather than the status code. The fix changes all affected DELETE methods to return return '', 204 which properly sets the HTTP status code to 204 with an empty response body.

Changes Made

Fixed DELETE methods in the following files:

  1. dify/api/controllers/console/tag/tags.py (line 123)

    • Fixed TagUpdateDeleteApi.delete() method
  2. dify/api/controllers/service_api/dataset/metadata.py (line 131)

    • Fixed DatasetMetadataServiceApi.delete() method
  3. dify/api/controllers/service_api/dataset/segment.py (lines 236, 502)

    • Fixed DatasetSegmentApi.delete() method (segment deletion)
    • Fixed DatasetChildChunkApi.delete() method (child chunk deletion)
  4. dify/api/controllers/service_api/dataset/dataset.py (lines 399, 560, 584, 608)

    • Fixed DatasetApi.delete() method (dataset deletion)
    • Fixed DatasetTagsApi.delete() method (tag deletion)
    • Fixed DatasetTagBindingApi.post() method (tag binding)
    • Fixed DatasetTagUnbindingApi.post() method (tag unbinding)
  5. dify/api/controllers/service_api/dataset/document.py (line 749)

    • Fixed DocumentApi.delete() method

Technical Details

Problem:

# ❌ Incorrect - Flask treats 204 as response body
return 204

Solution:

# ✅ Correct - Returns HTTP 204 No Content with empty body
return '', 204

This follows Flask's response tuple format: (response_body, status_code).

Screenshots

Before After
HTTP 200 OK
Response Body: 204
HTTP 204 No Content
Response Body: (empty)

Checklist

  • 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 make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods

Testing

All changes have been verified:

  • No linter errors introduced
  • All affected DELETE endpoints now return proper HTTP 204 No Content status
  • Response body is empty as expected for 204 responses

Related Issue

Fixes #<issue_number>

**Original Pull Request:** https://github.com/langgenius/dify/pull/32012 **State:** closed **Merged:** Yes --- # Pull Request > [!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 close https://github.com/langgenius/dify/issues/32011 This PR fixes a bug where Flask DELETE endpoints were returning the integer `204` as the response body instead of HTTP 204 No Content status code. In Flask, returning a single integer value like `return 204` causes Flask to treat it as the response body rather than the status code. The fix changes all affected DELETE methods to return `return '', 204` which properly sets the HTTP status code to 204 with an empty response body. ### Changes Made Fixed DELETE methods in the following files: 1. **`dify/api/controllers/console/tag/tags.py`** (line 123) - Fixed `TagUpdateDeleteApi.delete()` method 2. **`dify/api/controllers/service_api/dataset/metadata.py`** (line 131) - Fixed `DatasetMetadataServiceApi.delete()` method 3. **`dify/api/controllers/service_api/dataset/segment.py`** (lines 236, 502) - Fixed `DatasetSegmentApi.delete()` method (segment deletion) - Fixed `DatasetChildChunkApi.delete()` method (child chunk deletion) 4. **`dify/api/controllers/service_api/dataset/dataset.py`** (lines 399, 560, 584, 608) - Fixed `DatasetApi.delete()` method (dataset deletion) - Fixed `DatasetTagsApi.delete()` method (tag deletion) - Fixed `DatasetTagBindingApi.post()` method (tag binding) - Fixed `DatasetTagUnbindingApi.post()` method (tag unbinding) 5. **`dify/api/controllers/service_api/dataset/document.py`** (line 749) - Fixed `DocumentApi.delete()` method ### Technical Details **Problem:** ```python # ❌ Incorrect - Flask treats 204 as response body return 204 ``` **Solution:** ```python # ✅ Correct - Returns HTTP 204 No Content with empty body return '', 204 ``` This follows Flask's response tuple format: `(response_body, status_code)`. ## Screenshots | Before | After | |--------|-------| | HTTP 200 OK<br>Response Body: `204` | HTTP 204 No Content<br>Response Body: (empty) | ## Checklist - [ ] 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 `make lint` and `make type-check` (backend) and `cd web && npx lint-staged` (frontend) to appease the lint gods ## Testing All changes have been verified: - ✅ No linter errors introduced - ✅ All affected DELETE endpoints now return proper HTTP 204 No Content status - ✅ Response body is empty as expected for 204 responses ## Related Issue Fixes #<issue_number>
yindo added the pull-request label 2026-02-21 20:53:24 -05:00
yindo closed this issue 2026-02-21 20:53:24 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#33505