[PR #23168] minor fix: fix flask api resources only accept one resource for same url #30186

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

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

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

This PR fixes a Flask API routing issue where multiple resources were attempting to handle the same URL endpoint. The problem was that both AnnotationListApi and AnnotationCreateApi were registered to handle /apps/<uuid:app_id>/annotations, which Flask doesn't support - only one resource can be assigned per URL.

Changes made:

  • Renamed AnnotationListApi to AnnotationApi to better reflect its dual purpose
  • Moved the POST method from AnnotationCreateApi into the AnnotationApi class
  • Removed the redundant AnnotationCreateApi class entirely
  • Updated the API resource registration to use the consolidated AnnotationApi

This consolidation allows the /apps/<uuid:app_id>/annotations endpoint to properly handle both GET (list annotations) and POST (create annotation) operations within a single resource class, following Flask-RESTful best practices.

Motivation: Flask-RESTful requires that each URL pattern be handled by exactly one resource class. Having separate classes for the same endpoint was causing routing conflicts and preventing proper API functionality.

Screenshots

Before After
Two separate classes (AnnotationListApi and AnnotationCreateApi) handling the same URL endpoint Single consolidated AnnotationApi class handling both GET and POST methods for the same endpoint

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 dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/23168 **State:** closed **Merged:** Yes --- > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 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 This PR fixes a Flask API routing issue where multiple resources were attempting to handle the same URL endpoint. The problem was that both `AnnotationListApi` and `AnnotationCreateApi` were registered to handle `/apps/<uuid:app_id>/annotations`, which Flask doesn't support - only one resource can be assigned per URL. **Changes made:** - Renamed `AnnotationListApi` to `AnnotationApi` to better reflect its dual purpose - Moved the POST method from `AnnotationCreateApi` into the `AnnotationApi` class - Removed the redundant `AnnotationCreateApi` class entirely - Updated the API resource registration to use the consolidated `AnnotationApi` This consolidation allows the `/apps/<uuid:app_id>/annotations` endpoint to properly handle both GET (list annotations) and POST (create annotation) operations within a single resource class, following Flask-RESTful best practices. **Motivation:** Flask-RESTful requires that each URL pattern be handled by exactly one resource class. Having separate classes for the same endpoint was causing routing conflicts and preventing proper API functionality. ## Screenshots | Before | After | |--------|-------| | Two separate classes (`AnnotationListApi` and `AnnotationCreateApi`) handling the same URL endpoint | Single consolidated `AnnotationApi` class handling both GET and POST methods for the same endpoint | ## 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 `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:47:00 -05:00
yindo closed this issue 2026-02-21 20:47: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#30186