fix(api): Code-Based Extension cause error on position map sorting #7934
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #3981 and should continue to track the remain issue at #6528.
Note: The Code-Based Extension still does not appear on the interface.
I am submitting this PR mainly to explain my findings in the error, in order to save time for the next developer fixing the Code-Based Extension.
Checklist:
Important
Please review the checklist below before submitting your pull request.
dev/reformat
(backend) andcd web && npx lint-staged
(frontend) to appease the lint godsDescription
The issue is because there is None in the
position_map
.This piece of code assigns None to
position
and stores it inposition_map[extension_name]
when not entering the if statement.https://github.com/langgenius/dify/blob/main/api/core/extension/extensible.py#L60-L68
This implementation ensures that when no value is get from the
position_map
, it uses infinity as the default value.But there's None inside the
position_map
.Then it was taken out for comparison, and the error occurred.
https://github.com/langgenius/dify/blob/main/api/core/helper/position_helper.py#L120
Type of Change
Testing Instructions
This error occurs at startup and causes the program to exit immediately when you have Code-Based Extension in the external_data_tool folder.
After the correction, the error message disappeared and the api started normally.
(But the Code-Based Extension still doesn't show up at frontend.)