[PR #27206] fix Version 2.0.0-beta.2: Chat annotations Api Error #25506 #31714

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

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

State: closed
Merged: Yes


Refactor imports and enhance user context handling in service API.

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 #25506

  • Background: A 500 error occurred when calling annotation-related interfaces using the App Bearer Token. The reason is that validate_app_token set current_user to EndUser, while the service layer and interface permission checks expect Account.
  • Fix: When end-user context is not explicitly required, validate_app_token now logs in the tenant owner's account and sets current_tenant; the original logic remains unchanged when end-user context is needed.
  • Impact: Fixes the 500 error related to annotation interfaces, ensuring the interfaces can pass permission checks; maintains consistency with the behavior of validate_dataset_token.
  • Scope of changes: Only modify the authentication context injection logic in api/controllers/service_api/wraps.py; no database migration is required.
  • Verification: Rapidly inject and restart services via containers, test create/query/update/delete annotations using valid tokens, and return 201/200.
  • Risk and Compatibility: Ensure that tenants have an owner; this does not affect explicit end-user scenarios.
  • Follow-up: It is recommended that the service layer reduce its coupling with the current_user and provide documentation examples to illustrate the usage of end-users.

Screenshots

| Before | After |
|微信图片_20251020152055_301_32
|测试1|
| ... | 测试2|
| ... |测试三|

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/27206 **State:** closed **Merged:** Yes --- Refactor imports and enhance user context handling in service API. > [!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 #25506 - Background: A 500 error occurred when calling annotation-related interfaces using the App Bearer Token. The reason is that validate_app_token set current_user to EndUser, while the service layer and interface permission checks expect Account. - Fix: When end-user context is not explicitly required, validate_app_token now logs in the tenant owner's account and sets current_tenant; the original logic remains unchanged when end-user context is needed. - Impact: Fixes the 500 error related to annotation interfaces, ensuring the interfaces can pass permission checks; maintains consistency with the behavior of `validate_dataset_token`. - Scope of changes: Only modify the authentication context injection logic in api/controllers/service_api/wraps.py; no database migration is required. - Verification: Rapidly inject and restart services via containers, test create/query/update/delete annotations using valid tokens, and return 201/200. - Risk and Compatibility: Ensure that tenants have an owner; this does not affect explicit end-user scenarios. - Follow-up: It is recommended that the service layer reduce its coupling with the current_user and provide documentation examples to illustrate the usage of end-users. ## Screenshots | Before | After | |<img width="1068" height="782" alt="微信图片_20251020152055_301_32" src="https://github.com/user-attachments/assets/5954ba30-85e1-4ed6-9390-6405b0c88fd7" /> |<img width="1356" height="792" alt="测试1" src="https://github.com/user-attachments/assets/07b4f2a4-0ce2-416d-a6cd-28b57eb3cf87" />| | ... | <img width="1068" height="768" alt="测试2" src="https://github.com/user-attachments/assets/b54e2665-10a7-43af-aeeb-151290cbb222" />| | ... |<img width="1110" height="797" alt="测试三" src="https://github.com/user-attachments/assets/d4b35f1d-499c-4ed4-8e97-68269e7b97ea" />| ## 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:49:59 -05:00
yindo closed this issue 2026-02-21 20:49:59 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#31714