fix(admin): 修复 UpdateAccount 无法清空 credentials 和 extra 字段的问题#668
Open
wucm667 wants to merge 1 commit intoWei-Shaw:mainfrom
Open
fix(admin): 修复 UpdateAccount 无法清空 credentials 和 extra 字段的问题#668wucm667 wants to merge 1 commit intoWei-Shaw:mainfrom
wucm667 wants to merge 1 commit intoWei-Shaw:mainfrom
Conversation
之前使用 len(x) > 0 作为判断条件,导致传入空值时字段不会被更新, 无法通过 API 清空 credentials 和 extra 字段。 将判断条件改为 x != nil,使得传入空值时能正确清空对应字段。
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the UpdateAccount method where users cannot clear the credentials and extra fields by setting them to empty maps. The root cause is that the method used len(x) > 0 to check if these fields should be updated, which prevented empty maps from being saved.
Changes:
- Changed the condition from
len(input.Credentials) > 0toinput.Credentials != nilfor the Credentials field - Changed the condition from
len(input.Extra) > 0toinput.Extra != nilfor the Extra field
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
问题描述
在账号配置中,当用户开启自动透传(error pass-through)等功能后,再次编辑账号并尝试关闭该功能(将
credentials或extra置为空)时,保存不生效,字段值始终保持原有内容,导致已开启的功能无法关闭。复现步骤:
credentials或extra字段(开启自动透传等功能)并保存根本原因
UpdateAccount方法中使用len(x) > 0作为字段更新的判断条件,传入空切片/空 map 时长度为 0,条件不满足,字段被跳过不更新。修复方案
将判断条件从
len(x) > 0改为x != nil: