Skip to content
Open
Changes from all commits
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
3 changes: 3 additions & 0 deletions relay/relay_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ func videoFetchByIDRespBodyBuilder(c *gin.Context) (respBody []byte, taskResp *d
userId := c.GetInt("id")

originTask, exist, err := model.GetByTaskId(userId, taskId)
if !exist && model.IsAdmin(userId) {
originTask, exist, err = model.GetByOnlyTaskId(taskId)
}
Comment on lines +370 to +372
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Check query errors before applying admin fallback.

At Line [370], fallback runs on !exist even when GetByTaskId returned err. That can mask the original DB failure for admins by overwriting err with the second query result.

Suggested fix
 originTask, exist, err := model.GetByTaskId(userId, taskId)
-if !exist && model.IsAdmin(userId) {
+if err != nil {
+	taskResp = service.TaskErrorWrapper(err, "get_task_failed", http.StatusInternalServerError)
+	return
+}
+if !exist && model.IsAdmin(userId) {
 	originTask, exist, err = model.GetByOnlyTaskId(taskId)
-}
-if err != nil {
-	taskResp = service.TaskErrorWrapper(err, "get_task_failed", http.StatusInternalServerError)
-	return
+	if err != nil {
+		taskResp = service.TaskErrorWrapper(err, "get_task_failed", http.StatusInternalServerError)
+		return
+	}
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if !exist && model.IsAdmin(userId) {
originTask, exist, err = model.GetByOnlyTaskId(taskId)
}
originTask, exist, err := model.GetByTaskId(userId, taskId)
if err != nil {
taskResp = service.TaskErrorWrapper(err, "get_task_failed", http.StatusInternalServerError)
return
}
if !exist && model.IsAdmin(userId) {
originTask, exist, err = model.GetByOnlyTaskId(taskId)
if err != nil {
taskResp = service.TaskErrorWrapper(err, "get_task_failed", http.StatusInternalServerError)
return
}
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@relay/relay_task.go` around lines 370 - 372, The admin fallback currently
runs when !exist regardless of whether GetByTaskId returned an error; change the
logic in the block that calls model.GetByOnlyTaskId so it only executes when err
== nil && !exist && model.IsAdmin(userId). In other words, after calling
model.GetByTaskId(taskId) check err first and return/handle the error if
non-nil; only if err is nil and exist is false and model.IsAdmin(userId) call
model.GetByOnlyTaskId(taskId) to populate originTask/exist/err so you don't
overwrite or mask the original database error.

if err != nil {
taskResp = service.TaskErrorWrapper(err, "get_task_failed", http.StatusInternalServerError)
return
Expand Down