Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(worker): subject_action_group_resource excess data deleted group #307

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/database/dao/subject_template_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ func (m *subjectTemplateGroupManager) GetMaxExpiredAtBySubjectGroup(
return expiredAt.Int64, nil
}

// FIXME (nan): 使用 Max 聚合 SQL 且对 NULL 返回了 nil, 所以不存在 sql.ErrNoRows 的情况,
// 但上层调用点却使用了 sql.ErrNoRows 判断后进行各种逻辑处理,需要 Review 后决策如何修复
// Handle NULL case, for example, by returning a default value
return 0, nil
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/task/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,13 @@ func (h *groupAlterMessageHandler) alterSubjectActionGroupResource(subjectPK, ac
subjectPK, groupPK,
)
}
found := !errors.Is(err, service.ErrGroupMemberNotFound)
// Note:
// 由于 groupService.GetMaxExpiredAtBySubjectGroup 函数里的
// subjectTemplateGroupManager.GetMaxExpiredAtBySubjectGroup 使用 Max 聚合 SQL 且对 NULL 返回了 nil
// 所以导致 不可能存在 sql.ErrNoRows 的情况,即 ErrGroupMemberNotFound 也不可能出现
// 临时解决方案:由于 用户与用户组关系存在时 expiredAt 一定不为空,所以这里判断 expiredAt != 0 来表示用户还在用户组里
// FIXME (nan): 待底层 GetMaxExpiredAtBySubjectGroup 修复后,这里也对应进行修复
found := !errors.Is(err, service.ErrGroupMemberNotFound) && expiredAt != 0

// 查询group action授权资源实例
resourceMap, err := cacheimpls.GetGroupActionAuthorizedResource(
Expand Down
Loading