fix(task): 修复渠道配置多个key时无法获取任务的问题 - #2447
Conversation
WalkthroughThe key selection logic for FetchTask in the task video controller was modified. The code now prioritizes using Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
controller/task_video.go(1 hunks)
🔇 Additional comments (1)
controller/task_video.go (1)
55-56: No issue found. AllFetchTaskimplementations across adaptor types (vidu, suno, sora, kling, gemini, ali, hailuo, doubao, vertex, jimeng, and others) explicitly use thekeyparameter passed to the method in API requests, not any key stored duringInit(). The per-task key override at lines 77-82 works correctly.
| key := channel.Key | ||
|
|
||
| privateData := task.PrivateData | ||
| if privateData.Key != "" { | ||
| key = privateData.Key | ||
| } |
There was a problem hiding this comment.
Add nil check for task.PrivateData to prevent potential panic.
If task.PrivateData is nil, accessing privateData.Key on line 80 will cause a nil pointer dereference panic. Add a nil check before accessing the struct field.
Apply this diff to add a nil check:
key := channel.Key
privateData := task.PrivateData
- if privateData.Key != "" {
+ if privateData != nil && privateData.Key != "" {
key = privateData.Key
}📝 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.
| key := channel.Key | |
| privateData := task.PrivateData | |
| if privateData.Key != "" { | |
| key = privateData.Key | |
| } | |
| key := channel.Key | |
| privateData := task.PrivateData | |
| if privateData != nil && privateData.Key != "" { | |
| key = privateData.Key | |
| } |
🤖 Prompt for AI Agents
In controller/task_video.go around lines 77 to 82, the code reads
task.PrivateData without checking for nil which can cause a nil pointer
dereference; update the logic to first test if task.PrivateData != nil and only
then read privateData.Key, e.g. retrieve privateData into a local var after the
nil check (or check task.PrivateData.Key only when task.PrivateData != nil) and
set key to privateData.Key if present otherwise fall back to channel.Key.
视频任务的渠道配置了多个key时,获取任务详细信息报错。
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.