Repository navigation
fix(auth): 验证码关闭时 /captcha/get 返回 enable=false 而非报错 - #554
Merged
fastapiadmin merged 1 commit intoNov 4, 2026
Merged
fastapiadmin merged 1 commit into
fastapiadmin merged 1 commit into
Conversation
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.
问题
CAPTCHA_ENABLE=false(配置默认值)时,前端登录页调用GET /api/v1/system/auth/captcha/get拿到的是 400「未开启验证码服务」,前端只能落进catch分支。但响应模型
CaptchaOutSchema本来就有enable字段,就是用来表达「验证码是否启用」的;前端也是按data.enable决定要不要渲染滑块。功能关闭属于正常状态,不该是一个错误。原因
两处叠加,导致「返回
enable=false」这条路根本走不通:CaptchaService.get_captcha在CAPTCHA_ENABLE=false时直接raise CustomException,不走正常返回。CaptchaOutSchema.key是必填字段(min_length=1),即使想返回enable=false也构造不出合法响应(验证码关闭时按定义没有 key)。改动
backend/app/modules/system/auth/service.pyCaptchaOutSchema(enable=False),不再抛错backend/app/modules/system/auth/schema.pykey改为默认空字符串,允许未启用时没有 keybackend/tests/test_captcha_disabled.pysuccess=true、data.enable=false、data.key==""兼容性
data.enable判断是否渲染拼图。key允许为空字符串),且只影响「验证码关闭」这一场景 —— 该场景在此前返回的是错误响应,没有正常消费方会依赖它。验证
回归测试在修复前失败、修复后通过:
相关用例未受影响:
ruff check→ All checks passed